Using Filters
The Filters property of the FileDialog object returns a reference to the FileDialogFilters collection for the FileDialog.
This collection controls the types of files that are displayed in the dialog box.
By default there are 24 filters preset that the user can select from at the botton of the File Open dialog box
The clear method allows us to clear the default list and lets us add our own.
FileDialogFilter - Represents a type of file that can be selected in the file dialog box.
FileDialogFilters - A collection of FileDialogFilter objects that represent the different types of files that can be selected.
Dim objFileDialogFilters As Office.FileDialogFilters
Dim sFileName As String
Set objFileDialog = Application.FileDialog(msoFileDialogType.msoFileDialogOpen)
With objFileDialog
'define a Filters object
Set objFileDialogFilters = .Filters
With objFileDialogFilters
'clear the default filters
.Clear
'add a filter, all filters must start with an asterisk
.Add "Client Files", "*.xls"
.Add "Images", "*.png,*.jpg", 1
.Add "All Files", "*.*"
End With
'allow only one file to be selected
.AllowMultiSelect = False
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext