+ Reply to Thread
Results 1 to 8 of 8

Export each row as text file using first cell in row as title

  1. #1
    Registered User
    Join Date
    09-14-2011
    Location
    Grand Rapids, MI
    MS-Off Ver
    Excel 2003
    Posts
    4

    Export each row as text file using first cell in row as title

    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

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Export each row as text file using first cell in row as title

    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.

    Please Login or Register  to view this content.
    Steffen Thomsen

  3. #3
    Registered User
    Join Date
    09-14-2011
    Location
    Grand Rapids, MI
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Export each row as text file using first cell in row as title

    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

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Export each row as text file using first cell in row as title

    Please Login or Register  to view this content.



  5. #5
    Registered User
    Join Date
    09-14-2011
    Location
    Grand Rapids, MI
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Export each row as text file using first cell in row as title

    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

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Export each row as text file using first cell in row as title

    Books by Guy Hart Davis, John Walkenbach e.g.

  7. #7
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Export each row as text file using first cell in row as title

    Hi,

    can see you got the answer needed.

    Was in a bit of a hurry when i wrote it.

    This line
    Please Login or Register  to view this content.
    Should be changed to
    Please Login or Register  to view this content.
    Steffen Thomsen

  8. #8
    Registered User
    Join Date
    01-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Export each row as text file using first cell in row as title

    Hi Aaron,
    Thanks for asking the question.

    Hi snb,

    Thanks for the code. It was helpful to me as well. I had a query though. How to save the .txt file in UTF-8 format? Is this possible.

    Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1