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. Creates a new text file and overwrites the original text file with the data in the variable strData.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:
0 Comments
Leave a Reply. |