

The line below concatenates the string “Data to be appended” with the variable strData: For more information about concatenating string variables please see VBA Excel String Processing and Manipluation: It also concatenates a vbCrLf to the end of the line so a new line is created. The line below concatenates the current line in the original text file with the string in strData. The while loop below iterates through all the lines in the origianl text file and adds the data to the variable strData: The line below opens the original text file: For more information about writing data to text files please see Excel VBA Writing to a Text File.

Concatenates the string “Data to be appended” to the string variable strData. For more information about concatenating string variables please see VBA Excel String Processing and Manipluation.For more information about reading data from text files please see Excel VBA Reading Text Files. Reads all the lines of the original text file and stores them in the variable strData.StrData = strData + "Data to be appended" 'open the original text file to read the lines 'the final string to print in the text file

The code below will append the string “Data to be appended” to the end of the text file: The file is located in the “D:Temp with the name “Test.txt”. Assume we have the following data in a text file:
