Excel-VBA file operation 2

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.