Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Extract Workbook Data to Text File (multiple sheets)

Anyone have any code that can read through a selected workbook, save each
sheet to a text file (excluding header row) the code would need to append
each sheets data to that text file so the text file has all the data from the
workbook in one data file.

(I used the merge worksheets code from another post, but the files were so
large they exceeded Excel's capability - so now I need to go text).

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Extract Workbook Data to Text File (multiple sheets)

The macro below will export to a comma delimited file

HTH,
Bernie
MS Excel MVP


Sub ExportAllSheetsToPRN()

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
Dim mySht As Worksheet

fName = "C:\Documents and Settings\ExportAllSheets.prn"

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

Open fName For Output Access Write As #FNum

For Each mySht In ActiveWorkbook.Worksheets
With mySht.Range("A2", mySht.Range("A65536").End(xlUp).End(xlToRight))
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With


For RowNdx = StartRow To EndRow
WholeLine = mySht.Cells(RowNdx, StartCol).Text
For ColNdx = StartCol + 1 To EndCol
WholeLine = WholeLine & ", " & mySht.Cells(RowNdx, ColNdx).Text
Next ColNdx
Print #FNum, WholeLine
Next RowNdx
Next mySht

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

End Sub



"NYSA-HD" wrote in message
...
Anyone have any code that can read through a selected workbook, save each
sheet to a text file (excluding header row) the code would need to append
each sheets data to that text file so the text file has all the data from the
workbook in one data file.

(I used the merge worksheets code from another post, but the files were so
large they exceeded Excel's capability - so now I need to go text).

Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Extract Workbook Data to Text File (multiple sheets)

This worked fantastic! Thank you again for your help.



"Bernie Deitrick" wrote:

The macro below will export to a comma delimited file

HTH,
Bernie
MS Excel MVP


Sub ExportAllSheetsToPRN()

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
Dim mySht As Worksheet

fName = "C:\Documents and Settings\ExportAllSheets.prn"

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

Open fName For Output Access Write As #FNum

For Each mySht In ActiveWorkbook.Worksheets
With mySht.Range("A2", mySht.Range("A65536").End(xlUp).End(xlToRight))
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With


For RowNdx = StartRow To EndRow
WholeLine = mySht.Cells(RowNdx, StartCol).Text
For ColNdx = StartCol + 1 To EndCol
WholeLine = WholeLine & ", " & mySht.Cells(RowNdx, ColNdx).Text
Next ColNdx
Print #FNum, WholeLine
Next RowNdx
Next mySht

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

End Sub



"NYSA-HD" wrote in message
...
Anyone have any code that can read through a selected workbook, save each
sheet to a text file (excluding header row) the code would need to append
each sheets data to that text file so the text file has all the data from the
workbook in one data file.

(I used the merge worksheets code from another post, but the files were so
large they exceeded Excel's capability - so now I need to go text).

Thanks in advance.




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
Automated multiple text files into multiple sheets in one workbook Dr Dan Excel Discussion (Misc queries) 14 November 4th 07 11:32 AM
Multiple Sheets (Need to create 500 individual sheets in one workbook, pulling DATA Amaxwell Excel Worksheet Functions 4 August 17th 06 06:23 AM
extract data from a text file Spike Excel Programming 6 June 3rd 06 06:44 PM
Extract data from multiple sheets jmenche Excel Programming 0 December 8th 05 03:59 PM
Extract Data From Multiple Excel Files - One File Michael via OfficeKB.com Excel Programming 3 June 20th 05 08:24 PM


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