Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have used the code from http://www.cpearson.com/excel/imptext.htm and
adapted it as below. There are two sheets named BOMIN & BOMINh, and the macro produces two files, but they are both the same. Whichever sheet is current when the macro is run is saved twice but with different filenames. How do I save each sheet? My code is as below Public Sub SaveTextFiles() Dim FName As Variant Dim Sep As String Dim m As Integer Dim sStr As String Dim MyPath As String MyPath = "C:\SAPDATA\" For m = 1 To Sheets.Count FName = MyPath & Sheets(m).Name FName = sStr & FName & ".txt" Sep = vbTab ExportToTextFile CStr(FName), Sep, False, False Next m End Sub Any help would be appreciated. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The ExportToTextFile subroutine works on the activesheet.
So make sure you change sheets in your code: For m = 1 To Sheets.Count sheets(m).select '<--added FName = MyPath & Sheets(m).Name FName = sStr & FName & ".txt" Sep = vbTab ExportToTextFile CStr(FName), Sep, False, False Next m PeteN wrote: I have used the code from http://www.cpearson.com/excel/imptext.htm and adapted it as below. There are two sheets named BOMIN & BOMINh, and the macro produces two files, but they are both the same. Whichever sheet is current when the macro is run is saved twice but with different filenames. How do I save each sheet? My code is as below Public Sub SaveTextFiles() Dim FName As Variant Dim Sep As String Dim m As Integer Dim sStr As String Dim MyPath As String MyPath = "C:\SAPDATA\" For m = 1 To Sheets.Count FName = MyPath & Sheets(m).Name FName = sStr & FName & ".txt" Sep = vbTab ExportToTextFile CStr(FName), Sep, False, False Next m End Sub Any help would be appreciated. -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Dave, worked a treat.
"Dave Peterson" wrote: The ExportToTextFile subroutine works on the activesheet. So make sure you change sheets in your code: For m = 1 To Sheets.Count sheets(m).select '<--added FName = MyPath & Sheets(m).Name FName = sStr & FName & ".txt" Sep = vbTab ExportToTextFile CStr(FName), Sep, False, False Next m PeteN wrote: I have used the code from http://www.cpearson.com/excel/imptext.htm and adapted it as below. There are two sheets named BOMIN & BOMINh, and the macro produces two files, but they are both the same. Whichever sheet is current when the macro is run is saved twice but with different filenames. How do I save each sheet? My code is as below Public Sub SaveTextFiles() Dim FName As Variant Dim Sep As String Dim m As Integer Dim sStr As String Dim MyPath As String MyPath = "C:\SAPDATA\" For m = 1 To Sheets.Count FName = MyPath & Sheets(m).Name FName = sStr & FName & ".txt" Sep = vbTab ExportToTextFile CStr(FName), Sep, False, False Next m End Sub Any help would be appreciated. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Saving as text(tab delimited) file | New Users to Excel | |||
Macro that stores all sheets as tab-delimited text files | Excel Discussion (Misc queries) | |||
Macro to open *.dat files and save as .txt (comma delimited text files) | Excel Programming | |||
saving file as text(tab delimited)... | Excel Discussion (Misc queries) | |||
Saving spreadsheets as delimited text files | Excel Programming |