View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
PeteN PeteN is offline
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.