How to Edit a TXT File Using VBScript

Visual Basic Scripting (VBScript) files let you automate processes on your computer using small programs you can create an Windows Notepad. The VBScript file executes on a Windows computer and you can use the executable file to edit data in a text file. The "WriteLine" function adds data to the text file and saves the changes.

Instructions

    • 1

      Click the Windows "Start" button and type "notepad" in the search text box. Press "Enter" to open the text editor.

    • 2

      Create the file handler and open the text file. VBScript handles files using the "FSO" scripting object. The following code shows you how to set up the handler and open the text file:

      Set fso = CreateObject("Scripting.FileSystemObject")

      Set file = fso.GetFile("file.txt")

      Change the "file.txt" file name to the file you want to edit in the script.

    • 3

      Edit the text in the file. The following code adds the phrase "edited text file" to the opened "file.txt" file:

      file.WriteLine("edited text file")

    • 4

      After you complete the file edits, you must close the file. The following code completes the VBScript code:

      file.Close

    • 5

      Click the Notepad "File" menu and then click "Save." The "Save" dialog window appears. Type "editfile.vbs" in the "File Name" text box. Select "All Files" from the "File Type" drop-down box. Click "Save" to save the changes.

    • 6

      Double-click the file on your computer. The code executes on your computer so that you can test the changes.

Related Searches:

References

Comments

Related Ads

Featured