First of all, you should always use strong typed variables whenever possible. In this case, you can replace Object with Office.FileDialog .
To display the paths for each selected file, you need to loop through the SelectedItems collection. For example, you would add the following code:
Dim f As Office.FileDialog Set f = Application.FileDialog(3) f.AllowMultiSelect = True ' Show the dialog. If the method returns True, the user picked at least one file. ' If the method returns False, the user clicked Cancel. If f.Show Then MsgBox f.SelectedItems.Count & " file(s) were chosen." ' Display the full path to each file that was selected Dim i As Integer For i = 1 To f.SelectedItems.Count MsgBox f.SelectedItems(i) Next i End If
Please note that FileDialog also has other properties that you can set if configuration is required. For example, the .Title property allows .Title to specify the title that will be displayed in the title of the dialog in the title bar. You can also specify a filter using the .Filter property, which limits the type of files that the user can see and select in the dialog box. For example, if you want to limit the selection to only available databases, you can add the following code:
' Clear out the current filters f.Filters.Clear ' Add a few custom filters f.Filters.Add "Access Databases", "*.mdb" f.Filters.Add "All Files", "*.*"
source share