VBA macro that will open all Excel files in a folder
Macro that will open all Excel files in a folder. This functionality can be used to aggregate multiple workbooks into one or pull data from all workbooks in a folder. This demo example only opens the files. Within the loop you will add your logic to be performed on the opened workbook.
https://www.vba-market.com/LoopAllFiles_inFolder.xlsm
Sub LoopAllFiles_inFolder() MsgBox ("Select folder with files to loop") With Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show On Error Resume Next strpath = .SelectedItems(1) Err.Clear On Error GoTo 0 End With If Right(strpath, 1) <> "\" Then strpath = strpath + "\" ChDir strpath strextend = Dir("*.xls*") Do While strextend <> "" Set wb1 = Workbooks.Open(strpath & strextend) wb1.Activate ' add logic to be performed on open workbooks here strextend = Dir Loop End Sub
