Share via


How to: Open Text Files as Workbooks

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

You can open a text file as a workbook. You must pass in the name of the text file you want to open. You can specify several optional parameters, such as which row number to start parsing on and the column format of the data in the file.

Example

Me.Application.Workbooks.OpenText("C:\Test.txt", _
    StartRow:=3, _
    DataType:=Excel.XlTextParsingType.xlDelimited, _
    TextQualifier:=Excel.XlTextQualifier.xlTextQualifierNone, _
    Comma:=True)
this.Application.Workbooks.OpenText(@"C:\Test.txt",
    missing, 3,
    Excel.XlTextParsingType.xlDelimited,
    Excel.XlTextQualifier.xlTextQualifierNone,
    missing, missing, missing, true, missing, missing, missing, 
    missing, missing, missing, missing, missing, missing);

Compiling the Code

This example requires the following components:

  • A comma-delimited text file named Test.txt that contains at least three lines of text.

  • The text file Test.txt to be stored on drive C.

See Also

Tasks

How to: Open XML Files as Workbooks

How to: Open Workbooks

How to: Create New Workbooks

How to: Save Workbooks

How to: Close Workbooks

Concepts

Working with Workbooks

The Variable missing and Optional Parameters in Office Solutions