Chris has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Excel VBA Advanced course
Excel Forecasting and Data Analysis course
Running a macro from another workbook
Hi guys,
I am trying to create a macro that opens certain workbooks and triggers a macro to run, but I am having some problems.
I have written the below code. Which I though would work but no joy...
_____________________________________
Sub OpenAndRun ()
Workbooks.Open ("FilePath and FileName.xlsm")
Application.Run ("'FilePath and FileName.xlsm'!MacroName")
End Sub
______________________________________
The file opens as expected, but the macro will not run. Instead I get the below error message.
________________________________
Run-time error '1004':
Cannot run the macro 'FilePath and Macro Name'.
The macro may not be available in this workbook or all macros may be disabled.
________________________________
Please help!!
RE: Running a macro from another workbook
Hi Chris,
Thank you for the forum question.
I cannot see that you are doing something wrong. I copied your to lines and just did it between two test workbooks and it worked fine.
Well if the macro in the workbook is private then you cannot do it.
If the macro you try to execute starts:
Private Sub MacroName()
code to run
End Sub
If you want I can have a look at the workbooks.
You can send them to:
info@stl-training.co.uk
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector