Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Saving sheets as tab delimited text files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Saving sheets as tab delimited text files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Saving sheets as tab delimited text files

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
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
Saving as text(tab delimited) file Pam New Users to Excel 1 November 4th 09 01:30 AM
Macro that stores all sheets as tab-delimited text files [email protected] Excel Discussion (Misc queries) 2 February 14th 06 04:02 PM
Macro to open *.dat files and save as .txt (comma delimited text files) [email protected] Excel Programming 2 November 30th 05 05:50 AM
saving file as text(tab delimited)... Sevgi Excel Discussion (Misc queries) 1 April 6th 05 07:04 PM
Saving spreadsheets as delimited text files rwebster3[_2_] Excel Programming 2 April 22nd 04 01:46 AM


All times are GMT +1. The time now is 09:18 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"