LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Put Excel data to text file????

bretweir,

How about code to write a CSV? Select your range, and run the code below.

HTH,
Bernie
MS Excel MVP

Sub ExportToCSV()

Dim FName As String
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer

'Change the folder path here - will create a dated-name csv file
FName = "C:\Excel\CSV" & Format(Now(), " yyyy mmm dd") & ".csv"

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile

With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

Open FName For Output Access Write As #FNum

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If WholeLine = "" Then
WholeLine = Cells(RowNdx, ColNdx).Text
Else
WholeLine = WholeLine & "," & Cells(RowNdx, ColNdx).Text
End If
Next ColNdx
Print #FNum, WholeLine
Next RowNdx

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum

End Sub



"bretweir " wrote in message
...
This may be posted somewhere in this HUGE forum, but I couldn't find
it.

I want to create a macro that selects a range of my choosing, copies it
(or just puts it) to a text file of my choosing. This will be a sort
of data archiving for an ever changing spreadsheet.

Thanks in advance for any help.


---
Message posted from http://www.ExcelForum.com/



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing text file data into excel GradStudent N need Excel Discussion (Misc queries) 1 September 7th 07 09:44 AM
Rows of Data in Excel to Text File Russell Excel Discussion (Misc queries) 2 August 29th 07 05:10 PM
importing text file, removing data and outputting new text file Pal Excel Programming 8 February 27th 04 08:32 PM
Open delimited text file to excel without changing data in that file zohanc Excel Programming 1 October 3rd 03 01:06 AM
Adding Data from EXCEL to a TEXT file jason Excel Programming 3 August 27th 03 02:46 AM


All times are GMT +1. The time now is 01:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"