# Append Cell Values To Text Files

1. ## 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.

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

3. 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!)

4. - 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. 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. You are more than welcome. Please see my PM -- I'll follow up in due course.

7. Stefan.S

8. Thanks Mudraker, I am very happy with this solution!!!
Shg, got your PM. Thanks again for everything!

Stefan

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

#### 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