Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

running macro another workbook

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Running a macro from another workbook

Running a macro from another workbook

ResolvedVersion 2010

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

RE: Running a macro from another workbook

Jens,


I've actually got it working now.

I changed the name of the macro and then it worked...

Maybe it's because there was a number in the macro name??

Anyway thanks.


Chris

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Copying Values Without Formulas in Excel 2010

If you want to copy the contents of a cell but don't want to copy the formula with it then use the following simple method:

Press Ctrl+C to copy the values in the cell. On the Home tab, click Paste and then click Paste Values.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.