Workbooks. opentext (filename, origin, startrow, ype, textqualifier, delimiter, tab, semicolon, comma, space, other, otherchar, fieldinfo, textvisuallayout, delimiter, thousandsseparator, delimiter, local)
For more information about the meanings of the preceding parameters, see the help of VBA. In actual programming, it is generally not necessary to process these complex parameters. You can use a recording macro to obtain the VBA code for opening a text file. The specific method is to select "file-open", and then select Open Text File, the text import Wizard will appear, step by step, until the text is opened, stop recording.
The following is the code for recording macros:
Sub macro1 ()
'
'Macro1 macro
'Macro is recorded by MC system. Time:
'
'
Workbooks. opentext filename: = "F: callwindowproc.txt", origin: = xlwindows ,_
Startrow: = 1, datatype: = xldelimited, textqualifier: = xldoublequote ,_
Consecutivedelimiter: = false, Tab: = true, semicolon: = false, comma: = false _
, Space: = false, other: = false, fieldinfo: = array (1, 1 ),_
Trailingminusnumbers: = true
End sub
In actual programming, you only need to make the corresponding changes.
3. Open other files
Excel objects can also be used to open XML files and some database (such as Access) files, which correspond to XML files and require Versions later than excel2003.
The syntax of the openxml method is as follows:
Workbooks. openxml (filename, stylesheets, loadoption)
Filename string type, required. The name of the file to open.