Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Writing Text Files

I would like to write a vb macro that writes a text file from a row in
a worksheet with the first entry of the row as the file name. i.e.

A B
Filename1 Data to be written as file
Filename2 ... etc.

Any help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Writing Text Files

No built in capability to do that. You could copy the row2 data to a new
sheet, make that sheet active, then do a File SaveAS, naming the file with
the value in A1 of the original sheet.

Or you could use low level file io:

http://support.microsoft.com/support...eio/fileio.asp
File Access with Visual Basic® for Applications


--
Regards,
Tom Ogilvy

"RossD" wrote in message
m...
I would like to write a vb macro that writes a text file from a row in
a worksheet with the first entry of the row as the file name. i.e.

A B
Filename1 Data to be written as file
Filename2 ... etc.

Any help would be appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Writing Text Files

"Tom Ogilvy" wrote in message ...
No built in capability to do that. You could copy the row2 data to a new
sheet, make that sheet active, then do a File SaveAS, naming the file with
the value in A1 of the original sheet.



Thanks, Tom.
Actually, I made some progress on this since my post. I have:

Sub FileCreation()
Dim RowCount, FileNumber, File_Name
Range("A6").Select
RowCount = Range(Selection, Selection.End(xlDown)).Count
For n = 1 To RowCount
FileNumber = FreeFile ' Get unused file number.
Open ActiveCell.Value & ".txt" For Output As #FileNumber '
Create file name.
Write #FileNumber, ActiveCell.Offset(0, 1).Value ' Outputs
text.
Close #FileNumber ' Close file.
ActiveCell.Offset(1, 0).Select
Next n
End Sub

The only problem now is that the data in the text file had "" around
it. I don't know how to eliminate the quotation marks.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Writing Text Files

Use Print instead of Write in your output line. See Excel VBA help for
details.

--
Regards,
Tom Ogilvy


"RossD" wrote in message
om...
"Tom Ogilvy" wrote in message

...
No built in capability to do that. You could copy the row2 data to a

new
sheet, make that sheet active, then do a File SaveAS, naming the file

with
the value in A1 of the original sheet.



Thanks, Tom.
Actually, I made some progress on this since my post. I have:

Sub FileCreation()
Dim RowCount, FileNumber, File_Name
Range("A6").Select
RowCount = Range(Selection, Selection.End(xlDown)).Count
For n = 1 To RowCount
FileNumber = FreeFile ' Get unused file number.
Open ActiveCell.Value & ".txt" For Output As #FileNumber '
Create file name.
Write #FileNumber, ActiveCell.Offset(0, 1).Value ' Outputs
text.
Close #FileNumber ' Close file.
ActiveCell.Offset(1, 0).Select
Next n
End Sub

The only problem now is that the data in the text file had "" around
it. I don't know how to eliminate the quotation marks.



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
writing text to different cell after comparing tracktraining Excel Worksheet Functions 2 February 9th 09 11:47 PM
using wordwrap in excel for text writing ksu1955 Excel Worksheet Functions 1 November 10th 08 12:48 AM
q; Writing to files JIM.H. Excel Discussion (Misc queries) 1 April 23rd 07 10:36 PM
check writing text franz Excel Programming 1 January 31st 04 01:03 AM
writing to txt files Stuart[_12_] Excel Programming 1 December 5th 03 01:03 AM


All times are GMT +1. The time now is 08:41 AM.

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"