Excel VBA Tutorial: getopenfilename Method

Source: Internet
Author: User

The standard "open" dialog box is displayed to get the user's file name, without actually opening any file.

Expression. getopenfilename (filefilter, filterindex, title, buttontext, multiselect)

Expression is required. This expression returns an application object.

Filefilter variant type. Optional. A string that specifies the file filtering conditions.

This string consists of a file filter string and a file filter rule description expressed by a MS-DOS wildcard, separated by commas. Each string is listed in the "file type" drop-down list box. For example, the following string specifies two types of file filtering-text and macro loading: "text file (*. TXT ),*. TXT and add-in files (*. 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 this parameter is omitted, the default parameter values are "all files (*. *) and (*.*),*.*".

Filterindex variant type. Optional. Specifies the index number of the default file filtering conditions. The value ranges from 1 to the number of filtering conditions specified by filefilter. If this parameter is omitted or the value is greater than the available filtering quantity, the first file filtering condition is used.

Title variant type. Optional. Specify the title of the dialog box. If this parameter is omitted, "open" is used as the title.

(Optional) buttontext variant type. Only for Macintosh.

Multiselect variant type. Optional. If the value is true, multiple file names can be selected. If the value is false, only a single file name can be selected. The default value is false.

Description

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

This method may change the current drive or folder.

VBA example

This example shows the "open" dialog box for text files. If you select a file name, the selected file name is displayed in the message box.

 
Filetoopen = Application _. getopenfilename ("text files (*. txt), *. txt") if filetoopen <> false then msgbox "open" & filetoopenend if

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.