Click to Rate and Give Feedback
MSDN
MSDN Library
Office Development
Office 2003
Reference
Methods
O
 OpenText Method [Excel 2003 VBA Lan...

  Switch on low bandwidth view
Office Excel 2003 VBA Language Reference
OpenText Method [Excel 2003 VBA Language Reference]

Loads and parses a text file as a new workbook with a single sheet that contains the parsed text-file data.

expression.OpenText(FileName, Origin, StartRow, DataType, TextQualifier, ConsecutiveDelimiter, Tab, Semicolon, Comma, Space, Other, OtherChar, FieldInfo, TextVisualLayout, DecimalSeparator, ThousandsSeparator, TrailingMinusNumbers, Local)

expression Required. An expression that returns one of the objects in the Applies To list.

FileName  Required String. Specifies the file name of the text file to be opened and parsed.

Origin  Optional Variant. Specifies the origin of the text file. Can be one of the following XlPlatform constants: xlMacintosh, xlWindows, or xlMSDOS. Additionally, this could be an integer representing the code page number of the desired code page. For example, "1256" would specify that the encoding of the source text file is Arabic (Windows). If this argument is omitted, the method uses the current setting of the File Origin option in the Text Import Wizard.

StartRow  Optional Variant. The row number at which to start parsing text. The default value is 1.

DataType  Optional Variant. Specifies the column format of the data in the file. Can be one of the following XlTextParsingType constants: xlDelimited or xlFixedWidth. If this argument is not specified, Microsoft Excel attempts to determine the column format when it opens the file.

ConsecutiveDelimiter  Optional Variant. True to have consecutive delimiters considered one delimiter. The default is False.

Tab  Optional Variant. True to have the tab character be the delimiter (DataType must be xlDelimited). The default value is False.

Semicolon  Optional Variant. True to have the semicolon character be the delimiter (DataType must be xlDelimited). The default value is False.

Comma  Optional Variant. True to have the comma character be the delimiter (DataType must be xlDelimited). The default value is False.

Space  Optional Variant. True to have the space character be the delimiter (DataType must be xlDelimited). The default value is False.

Other  Optional Variant. True to have the character specified by the OtherChar argument be the delimiter (DataType must be xlDelimited). The default value is False.

OtherChar  Optional Variant (required if Other is True). Specifies the delimiter character when Other is True. If more than one character is specified, only the first character of the string is used; the remaining characters are ignored.

TextVisualLayout  Optional Variant. The visual layout of the text.

DecimalSeparator  Optional Variant. The decimal separator that Microsoft Excel uses when recognizing numbers. The default setting is the system setting.

ThousandsSeparator  Optional Variant. The thousands separator that Excel uses when recognizing numbers. The default setting is the system setting.

TrailingMinusNumbers  Optional Variant. Specify True if numbers with a minus character at the end should be treated as negative numbers. If False or omitted, numbers with a minus character at the end are treated as text.

Local  Optional Variant. Specify True if regional settings of the machine should be used for separators, numbers and data formatting.

Example

This example opens the file Data.txt and uses tab delimiters to parse the text file into a worksheet.

Workbooks.OpenText filename:="DATA.TXT", _
    dataType:=xlDelimited, tab:=True
		




© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker