In this article, we will create a macro to open multiple files with a file dialog box.
We have created the macro “opening_multiple_file” to open multiple files. A user can click on “Open Multiple files” button to run the macro.
We have created the macro “opening_multiple_file” to open multiple files. A user can click on “Open Multiple files” button to run the macro. It opens the file dialog box from where a user can select multiple excel files, which he wants to open.
Once all the files are selected, click on “OK” button to open all the selected files.
The above code is used to open the file dialog box.
.AllowMultiSelect = True
In above code, AllowMultipleSelect property is set true to enable multiple selection in file dialog box.
.Filters.Add "Excel Files", "*.xls*"
In above code, filter for file dialog box is set to select Excel Files only.
If .Show = True Then
The above code is used to check whether a user presses “OK” or “Cancel” button in file dialog box.
The above code is used to open the selected Excel file.
Please follow below for the code
Option Explicit Sub opening_multiple_file() Dim i As Integer 'Opening File dialog box With Application.FileDialog(msoFileDialogFilePicker) 'Enabling multiple files select .AllowMultiSelect = True .Filters.Clear 'Only Excel files can be selected .Filters.Add "Excel Files", "*.xls*" If .Show = True Then For i = 1 To .SelectedItems.Count 'Opening selected file Workbooks.Open .SelectedItems(i) Next i End If End With End Sub
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at email@example.com
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.