Hello, Excel Forum!
I posted a question in an old forum and was kindly instructed that I was in violation of the forum rules, so I am now creating a new thread with a more concise question.
I have a .CSV file with two text columns; one serving as a title and the other as a body paragraph. For example:
_A_________ B__________
1 Title______ Content__________
2 Red______ This is a sentence...
3 Orange____And another sentence...
4 Yellow____ Yet another...
5 Green_____You get the idea...
I am hoping there is a way to save each of the rows in the worksheet as a separate document, preferably a .txt file but a Word .doc or .rtf would be fine, and use the text from the first column to title the file and the text from the second column to populate the content of the document. I'm not very familiar with VisualBasic or macros but would be willing to learn if pointed in the right direction. Any help is greatly appreciated.
Thanks
-Aaron
Last edited by aaronmb; 10-06-2011 at 12:30 PM. Reason: Solved with a macro
Hi,
you could do something like this
This code loops threw your usedrange on sheet 1 and writes a text file using cell in column a as save title and column b as content.
Steffen ThomsenFor each cell in Sheets(1).range("A1:A" & Sheets(1).UsedRange.Rows.Count) saveText = cell.text open "E:\yourfolder\" & saveText & ".txt" for output as #1 Print #1,cell.offset(1,0).Text Close #1 next cell
Hi Stephen
Thank you for your quick response. I gave the macro a try but there seems to be a missing step somewhere. Everything works as it should except I think the offset command is looking to the next cell down in the column instead of the adjacent cell in the row. I think I can make it work by simply moving all of the information into a single column with alternating title/content rows but if you know of a way to have the offset occur horizontally instead of vertically I would appreciate your expert advice.
Thanks again
-aaron
Sub snb() sn= Sheets(1).usedrange for j=1 to ubound(sn) open "E:\yourfolder\" & sn(j,1) & ".txt" for output as #1 Print #1, sn(j,2) Close #1 next End Sub
That did it! Many thanks. One of these days I'll have to sit down with a book and figure out exactly what all that programming language means should I ever want to modify it. If you recommend any guides to learning VBA-code I wouldn't mind taking a look at one.
-Aaron
Books by Guy Hart Davis, John Walkenbach e.g.
Hi,
can see you got the answer needed.
Was in a bit of a hurry when i wrote it.
This line
Should be changed tocell.offset(1,0).Text
Steffen Thomsencell.offset(0,1).Text
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks