HELP! I revised a macro for a client, and now it gives him a run-time error. Macro used to allow user to select ONE file for processing. Client wanted to select multiple files, and have the macro process them one after another. So I just added a loop and changed the code to allow selection of multiple files. The loop increments a counter to open and process each file.
Problem: The macro runs fine for me (it will open and process multiple files as desired, with NO errors). I'm running Excel 2007. Client is running Microsoft 365 and the macro bombs for him. It opens and processes the first file just fine, but throws the run-time error when it tries to get the filename and path for the second selected item. Any ideas on what the cause / fix could be?
Here is the relevant portion of the code. Sets a run-time error 5 (Invalid procedure call or argument) at the "FilePath = ..." statement, when FileCounter = 2
...
Call Application.FileDialog(msoFileDialogOpen).Filters.Clear
Call Application.FileDialog(msoFileDialogOpen).Filters.Add("Excel Files", "*.xls;*.xlsx")
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Title = "Select the Files to Process"
FileOK = .Show
FilesCount = .SelectedItems.Count
End With
If FileOK = 0 Then GoTo ExitThisSub
' Open and process each file (one at a time)
For FileCounter = 1 To FilesCount
FilePath = Application.FileDialog(msoFileDialogOpen).SelectedItems(FileCounter)
' Open the next file and check for correct format
Workbooks.Open (FilePath)
Set OpenedFile = ActiveWorkbook
...
Bookmarks