Using Application.Run in Excel VBA when workbook name contains spaces
will work (run the macro called Macro1 in the MyWorkBook.xls file)
Application.Run "My Work Book.xls!Macro1"
will not (if the workbook name contains spaces, Excel says "the macro cannot be found").
I just spent hours figuring out that it's the spaces causing this problem...
Is there a way around this without renaming the file?
Use single quotes surrounding the filename:
Application.Run "'My Work Book.xls'!Macro1"
Replace each of the spaces with %20
Here File_name is the name of the file for which you want to call your macro
- Application.run "'"+File_name+"'"+"!Macro"
- Single quote in between double quote followed by + File_name + single quote in between double quote + your macro name in between double quotes.