LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Exporting txt file

I'm confused about whether you want a file for each row or for each column.

If you really want the rows, maybe this will help:

Option Explicit
Sub notebook_save()
Dim CurWks As Worksheet
Dim NewWks As Worksheet
Dim iRow As Long
Dim LastRow As Long

Set CurWks = ActiveSheet
Set NewWks = Workbooks.Add(1).Worksheets(1)

With CurWks
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = 1 To LastRow
.Rows(iRow).Copy _
Destination:=NewWks.Range("a1")
NewWks.Parent.SaveAs Filename:="c:\save" & iRow & ".txt", _
FileFormat:=xlTextMSDOS
Next iRow
End With

NewWks.Parent.Close savechanges:=False
End Sub

ps.

Is "C:\save" a folder or the prefix for the name?
maybe...
Filename:="c:\save\" & iRow & ".txt"
or
Filename:="c:\save\" & format(iRow,"00000") & ".txt"

ajshap1 wrote:

I have multiple rows within a worksheet and need them to automatically
save into a separate txt file.

Example:

I have a workbook with rows b-z. Instead of taking each of the rows
and copying and pasting it into another separate excel file, then
saving in a txt format, is there a way to automate this?

So that the following will occur:

Column B 950 line is one file
Column C 950 lines is another
column D lines in another txt file.....etc

I have some code listed below, however, it reads the first column cell
by cell. It does not group column by column grouping all data within
that column as on txt file

Thanks

Code:
Sub notebook_save()
Set wkbk = Workbooks.Add
Sheets("Sheet1").Select
RowCount = Cells(Cells.Rows.Count, "a").End(xlUp).Row
For i = 1 To RowCount
Sheets("Sheet1").Select
Range("a" & i).Select
ActiveCell.EntireRow.Copy
Sheets("Sheet2").Select
Range("a1").Select
ActiveSheet.Paste
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs _
Filename:="c:\save" & i & ".txt", _
FileFormat:=xlTextMSDOS
wkbk.Close
Next
Application.DisplayAlerts = True
End Sub


--

Dave Peterson
 
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
Exporting to CSV file Paul Bytes Excel Discussion (Misc queries) 1 January 3rd 07 04:21 PM
Exporting a PDF file monkster Excel Discussion (Misc queries) 0 May 2nd 06 08:18 PM
Exporting to csv file Geri Excel Discussion (Misc queries) 5 September 6th 05 02:48 PM
Exporting to Word in a csv file Brad Excel Discussion (Misc queries) 5 August 20th 05 06:53 PM
Exporting CSV file to unicode .txt file - " around strings Paul Excel Discussion (Misc queries) 1 June 14th 05 12:27 AM


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