You can download the file and code related to this article here. The open file dialog is initially displayed:Īfter the text file is opened and its lines are stored in the variable strData an input dialog is displayed, prompting the user to input the data to be appended to the original text file: StrDataToAppend = InputBox("Data to Append") StrPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1) IntResult = Application.FileDialog(msoFileDialogOpen).Show 'disallow user from selecting multiple filesĪpplication.FileDialog(msoFileDialogOpen).AllowMultiSelect = FalseĬall Application.FileDialog(msoFileDialogOpen).Filters.ClearĬall Application.FileDialog(msoFileDialogOpen).Filters.Add("Text " & _ For more information about the open file dialog please see Excel VBA Open File Dialog: The input dialog prompts the user to input the data to be appended to the text file. The open file dialog prompts the user to select the location for the input file. This example adds 2 dialogs to the previous example: The lines below create a new text file, fills the new text file with the variable strData and overwrites the original file: 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.