Writing Text Files

R

RossD

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.
 
R

RossD

Tom Ogilvy said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top