Excel VBA Select File Dialog Box

Source: Internet
Author: User
Sub XXX () dim Arr () Arr = application. getopenfilename ("all payment files (*. XLS ;*. XLSX ;*. CSV ),*. XLS ;*. XLSX ;*. CSV, Excel file (*. XLS ),*. xls, excel2007 file (*. XLSX ),*. XLSX, CSV file (*. CSV ),*. CSV "," select file ", true) for I = lbound (ARR) to ubound (ARR) cells (I, 1 ). value = Arr (I) nextend sub

In the preceding example, select multiple files.

The following is the original Microsoft text

Application. getopenfilename Method

Display standard"Open"Dialog box, and get the user file name, without actually opening any file.

Syntax

Expression. Getopenfilename (Filefilter,
Filterindex,Title,Buttontext,Multiselect)

ExpressionOne representativeApplicationObject variable.

Parameters

Name Required/optional Data Type Description
Filefilter Optional Variant A string that specifies the file filtering conditions.
Filterindex Optional Variant Specifies the index number of the default file filtering conditions. The value ranges from 1FilefilterThe number of specified filtering conditions. If this parameter is omitted, or the value of this parameter is greater than the number of available filtering conditions, the first file filtering condition is used.
Title Optional Variant Specify the title of the dialog box. If this parameter is omitted, the title is "open ".
Buttontext Optional Variant Only for Macintosh.
Multiselect Optional Variant IfTrueYou can select multiple file names. IfFalseOnly one file name can be selected. The default value is
False.

Return Value
Variant

Description

InFilefilterThe string passed in the parameter is composed of a file filter string pair and a MS-DOS wildcard file filter followed by a comma separated. Each string is in"File type"It is listed in the drop-down list box. For example, the following string specifies two file filtering-text and macro loading: "text file (*. TXT ),*. TXT: loads the macro file (*. xla ),*. xla ".

To use multiple MS-DOS wildcard expressions for a single file filter type, separate them with semicolons. For example, "Visual Basic file (*. Bas; *. txt), *. Bas; *. txt ".

If omittedFilefilterThe default value of this parameter is "all files (*.*),*.*".

This method returns the selected file name or the name entered by the user. The returned name may contain the path description. IfMultiselectIsTrueThe returned value is an array containing all selected file names (even if only one file name is selected ). If the user cancels the dialog box, the value is
False.

This method may change the current drive or folder.

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.