Return to VBA Code Examples

VBA Open Text File with OpenTextFile

This tutorial will demonstrate how to use the OpenTextFile method of the FileSystemObject.

Open a Text File

This lesson uses the FileSystemObject. In order to use it, you will need to set a reference to the VB script run-time library. See here for more information.

You can open an existing text file for reading:

and then paste its content to the current worksheet’s first cell, e.g.:

For more options with ForReading mode see here.

In ForWriting mode you can replace an existing file’s content with new data but you can’t read from the file.

For more options with ForWriting mode see here.

In ForAppending mode you can write to the end of the file. You can’t read from this file.

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!