+ Reply to Thread
Results 1 to 8 of 8

Append Cell Values To Text Files

  1. #1
    Registered User
    Join Date
    08-15-2008
    Location
    Belgium
    Posts
    7

    Append Cell Values To Text Files

    I have over 1,000 text files on my hard drive.
    I need to add a different line of text (a cell value) to the bottom of each of these text files (without opening them)...

    I have the following setup in mind...

    Column A
    all text file names, including path:
    C:\folder1\text1.txt
    C:\folder1\text2.txt
    C:\folder1\text3.txt
    etc...

    Column B
    all the different values to append at the end of the "same row" text file:
    this text (to append at the end of text1.txt)
    some other text (to append at the end of text2.txt)
    this text variation (to append at the end of text3.txt)
    etc...

    So my Excel 2003 sheet should look like this...

    row1 - (A)C:\folder1\text1.txt - (B)this text
    row2 - (A)C:\folder1\text2.txt - (B)some other text
    row3 - (A)C:\folder1\text3.txt - (B)this text variation
    etc...

    Running the macro should do the following (row per row)
    - append the cell value from column B to the text file in cell column A
    - save the newly created text file in C:\folder2\ under the same file name.

    I hope this makes sense.

    Thanks for your help!!!

    Stefan
    P.S. I use Excel 2003 and I have no VBA programming skills, so..., much obliged to anyone who can help me out here!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Try this:
    Please Login or Register  to view this content.
    It assumes you have a header in row 1.

    Adding a Macro to a Code Module
    1. Copy the code from the post
    2. Press Alt+F11 to open the Visual Basic Editor (VBE)
    3. From the menu bar in the VBE window, do Insert > Module
    4. Paste the code in the window that opens
    5. Close the VBE to return to Excel

  3. #3
    Registered User
    Join Date
    08-15-2008
    Location
    Belgium
    Posts
    7
    Hi Shg,

    Thank you for your fantastic input...
    I tested your code and it works flawlessly for the specified range (A2-A...)
    I changed A2 into A1 for my own convenience...

    I know it's impolite to ask you for another favor, but...

    - is it possible to add a line break before the inserted text?
    - could the newly created file automatically be saved in C:\folder2\

    Thank you SOOOOOOOOOO Much!!!!


    Stefan
    P.S. It would also be nice to get rid of the quotes that automatically enclose the appended text (thanks again!)
    Last edited by Stefan.S.; 08-16-2008 at 02:29 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    - is it possible to add a line break before the inserted text?
    P.S. It would also be nice to get rid of the quotes that automatically enclose the appended text (thanks again!)
    Please Login or Register  to view this content.
    - could the newly created file automatically be saved in C:\folder2\
    That one I leave to you. You would need to copy the unmodified files to folder2, then open and append those files.

  5. #5
    Registered User
    Join Date
    08-15-2008
    Location
    Belgium
    Posts
    7
    Hi Shg,

    Thank you! Thank you! thank you so much !!!

    What a nice and generous person you are!

    That code works just Perfect!

    Thanks again,

    Stefan

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You are more than welcome. Please see my PM -- I'll follow up in due course.

  7. #7
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Stefan.S

    It's good to see you were able to get an answer to your problem despite me accidentally deleting your previous thread
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  8. #8
    Registered User
    Join Date
    08-15-2008
    Location
    Belgium
    Posts
    7
    Thanks Mudraker, I am very happy with this solution!!!
    Shg, got your PM. Thanks again for everything!

    Stefan

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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