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

resolvedResolved · High Priority · Version 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:

Make a quick copy of a worksheet

Hold down the Ctrl key, then click and drag on a sheet tab to make a copy of that sheet. Though this process usefully copies the formats of the original sheet, note that any Range Names you have on the original sheet will be duplicated too.

To make a copy of a worksheet's contents and formats without duplicating range names: (1) Ensure that you have a blank worksheet to paste to. (2) On the sheet to copy, click on the sheet selection square to the left of Column A's heading to select the whole sheet. (2) Copy the whole sheet. (3) Paste to the blank worksheet.



View all Excel hints and tips


Server loaded in 0.05 secs.