GetOpenFilename Method Excel 2003 VBA Language Reference. 2 minutes to readIn this articleDisplays the standard Open dialog box and gets a file name from the user without actually opening any files.expression.GetOpenFilename( FileFilter., FilterIndex, Title, ButtonText, MultiSelect)expression Required. An expression that returns an Application object.FileFilter Optional Variant. A string specifying file filtering criteria.This string consists of pairs of file filter strings followed by the MS-DOS wildcard file filter specification, with each part and each pair separated by commas.
Each separate pair is listed in the Files of type drop-down list box. For example, the following string specifies two file filters—text and addin: 'Text Files (.txt),.txt,Add-In Files (.xla),.xla'.To use multiple MS-DOS wildcard expressions for a single file filter type, separate the wildcard expressions with semicolons; for example, 'Visual Basic Files (.bas;.txt),.bas;.txt'.If omitted, this argument defaults to 'All Files (.),.' .FilterIndex Optional Variant. Specifies the index numbers of the default file filtering criteria, from 1 to the number of filters specified in FileFilter. If this argument is omitted or greater than the number of filters present, the first file filter is used.Title Optional Variant. Specifies the title of the dialog box.
If this argument is omitted, the title is 'Open.' ButtonText Optional Variant. Macintosh only.MultiSelect. Optional Variant. True to allow multiple file names to be selected. False to allow only one file name to be selected.
The default value is. False RemarksThis method returns the selected file name or the name entered by the user. The returned name may include a path specification. If MultiSelect is True, the return value is an array of the selected file names (even if only one filename is selected). Returns False if the user cancels the dialog box.This method may change the current drive or folder. ExampleThis example displays the Open dialog box, with the file filter set to text files.
If the user chooses a file name, the code displays that file name in a message box. FileToOpen = Application.GetOpenFilename('Text Files (.txt),.txt')If fileToOpen False ThenMsgBox 'Open ' & fileToOpenEnd IfApplies to See Also.
I'm looking to set a default filename in GetOpenFilename. I'm using GetOpenFilename because it was in an example for using UNC paths (which I require) and from what I've read you cannot do that with ChDir or ChDrive using FileDialog.
Is there anything that exists that will allow presetting of the filename and work with UNC paths?I've tried sticking the filename into the FileFilter section of GetOpenFilename and that does not work. From what I have found it looks like this may not be possible but my limited knowledge of VBA may be the issue as well.I'm stuck with using UNC because the data is located on a network and not everyone maps it to the same drive or even maps it at all. In Excel if you look in Application.Dialogs you'll find a long list of predefined dialog boxes used in Excel that you can call upon.
GetOpenFilename is the same situation, because it is predefined, the customization options are minimal.To use the generic file dialog box (i.e. Not custom within Excel) you can use Application.FileDialog(msoFileDialogOpen), this will allow for further customisation including the initial filename text. Download hma vpn setup.
Public Sub SampleDim Dlg As FileDialogSet Dlg = Application.FileDialog(msoFileDialogOpen)Dlg.InitialFileName = 'Sample'Dlg.ShowSet Dlg = NothingEnd Sub.
Hey guys,I've just run into an issue with GetOpenFilename, and I can't get past it as of yet.I'm trying to open the window in a specific directory, but I want to save the path that the user intially has, so that I can reset it there after I'm done.