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