Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default export many sheets to text files

I'm trying to adapt code from http://www.cpearson.com/excel/imptext.htm to
export 150 spreadheets of data to separate text files.
It seems to work as long as I type the name of each text file into the save
as box. I was hoping someone could show me how to alter the code so that the
name of the text file could set automatically based on either the contents of
cell A1 or the sheet name of the sheet being exported.
Here's what I have so far:

Public Sub DoTheExport()
Dim FName As Variant
Dim Sep As String
Dim m As Integer

For m = 1 To Sheets.Count
ChDir "C:\Documents and Settings\TJ\Desktop\QualDatTEXT"
FName = Sheets(m).Range("A1") 'I know this is wrong-I don't know how to fix it
FName = Application.GetSaveAsFilename()
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If

Sep = ","

ExportToTextFile CStr(FName), Sep, False
Next m
End Sub


--
tj
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default export many sheets to text files

Get rid of the line

FName = Application.GetSaveAsFilename()

Other than that, your code looks OK.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"tjtjjtjt" wrote in message
...
I'm trying to adapt code from
http://www.cpearson.com/excel/imptext.htm to
export 150 spreadheets of data to separate text files.
It seems to work as long as I type the name of each text file
into the save
as box. I was hoping someone could show me how to alter the
code so that the
name of the text file could set automatically based on either
the contents of
cell A1 or the sheet name of the sheet being exported.
Here's what I have so far:

Public Sub DoTheExport()
Dim FName As Variant
Dim Sep As String
Dim m As Integer

For m = 1 To Sheets.Count
ChDir "C:\Documents and Settings\TJ\Desktop\QualDatTEXT"
FName = Sheets(m).Range("A1") 'I know this is wrong-I don't
know how to fix it
FName = Application.GetSaveAsFilename()
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If

Sep = ","

ExportToTextFile CStr(FName), Sep, False
Next m
End Sub


--
tj



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default export many sheets to text files

Thanks.

tj

"Chip Pearson" wrote:

Get rid of the line

FName = Application.GetSaveAsFilename()

Other than that, your code looks OK.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"tjtjjtjt" wrote in message
...
I'm trying to adapt code from
http://www.cpearson.com/excel/imptext.htm to
export 150 spreadheets of data to separate text files.
It seems to work as long as I type the name of each text file
into the save
as box. I was hoping someone could show me how to alter the
code so that the
name of the text file could set automatically based on either
the contents of
cell A1 or the sheet name of the sheet being exported.
Here's what I have so far:

Public Sub DoTheExport()
Dim FName As Variant
Dim Sep As String
Dim m As Integer

For m = 1 To Sheets.Count
ChDir "C:\Documents and Settings\TJ\Desktop\QualDatTEXT"
FName = Sheets(m).Range("A1") 'I know this is wrong-I don't
know how to fix it
FName = Application.GetSaveAsFilename()
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If

Sep = ","

ExportToTextFile CStr(FName), Sep, False
Next m
End Sub


--
tj




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default export many sheets to text files

Without knowing what is in cell A1, this is a possibility

Public Sub DoTheExport()
Dim FName As String
Dim Sep As String
Dim m As Integer
Dims sStr as String

sStr = "C:\Documents and Settings\TJ\Desktop\QualDatTEXT\"
chdrive sStr
chdir sStr

For m = 1 To Sheets.Count
FName = Sheets(m).Range("A1").Text
' or FName = Sheets(m).Name
FName = sStr & FName & ".txt"
Sep = ","

ExportToTextFile FName, Sep, False
Next m
End Sub

--
Regards,
Tom Ogilvy


"tjtjjtjt" wrote in message
...
I'm trying to adapt code from http://www.cpearson.com/excel/imptext.htm to
export 150 spreadheets of data to separate text files.
It seems to work as long as I type the name of each text file into the

save
as box. I was hoping someone could show me how to alter the code so that

the
name of the text file could set automatically based on either the contents

of
cell A1 or the sheet name of the sheet being exported.
Here's what I have so far:

Public Sub DoTheExport()
Dim FName As Variant
Dim Sep As String
Dim m As Integer

For m = 1 To Sheets.Count
ChDir "C:\Documents and Settings\TJ\Desktop\QualDatTEXT"
FName = Sheets(m).Range("A1") 'I know this is wrong-I don't know how to

fix it
FName = Application.GetSaveAsFilename()
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If

Sep = ","

ExportToTextFile CStr(FName), Sep, False
Next m
End Sub


--
tj



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
export sheets to multiple new files Tanya Excel Discussion (Misc queries) 8 April 20th 09 10:00 PM
export multiple sheets to multiple excel files Tanya Excel Discussion (Misc queries) 1 April 20th 09 08:57 PM
Macro that stores all sheets as tab-delimited text files [email protected] Excel Discussion (Misc queries) 2 February 14th 06 04:02 PM
Export sheets as JPEG files through a dialog box (Problems) Tim[_36_] Excel Programming 6 May 21st 04 01:26 AM
Copy text files into multiple sheets of 1 workbook Steve[_56_] Excel Programming 0 January 14th 04 08:30 PM


All times are GMT +1. The time now is 10:55 PM.

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

About Us

"It's about Microsoft Excel"