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

running macro another spreadshee

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

Running a Macro from another spreadsheet

ResolvedVersion 2007

Tom has attended:
Excel VBA Intro Intermediate course
Access Intermediate course

Running a Macro from another spreadsheet

Hi,

How do you open a spreadsheet and run a macro in it from a macro in another spreadsheet without effecting this other spreadsheet?

Thanks,

Tom





RE: Running a Macro from another spreadsheet

Hi Tom

Thanks for your question.

You could open the worksheet from your macro in another worksheet very easily with something like the following

Workbooks(NAME).sheets(Name).activate


You could then run your second macro by calling it in the activate event of that worksheet.

Hope this helps

Regards

Stephen

RE: Running a Macro from another spreadsheet

Hi Stephen,

Thanks very much for your help. Would you mind explaining a little further. I have tried the following...

Sub RunMacro()

Workbooks("Dist Plan 103a").Sheets("Reforecast").Activate

Application.Run (Workbooks("Dist Plan 103a")!reforecast_figures)

End Sub


Where reforecast_figures is the macro and it doesnt like it, it says Subscript Out of Range.

Sorry about this,

tom

RE: Running a Macro from another spreadsheet

Hi Tom

Sorry for the delay in getting back, I have been on a week's leave.

Your first line of code is fine. However your reforcast_figures macro needs to be called from the open event of your "Dist Plan 103a" workbook. Open this workbook and go to the VBE. In the project explorer double click on the workbook object. Above the code window you will have 2 combo boxes. The left most one will probably say "General". Click on the combo and select Workbook. This should then automatically create an on open sub procerdure. In this procedure type
[code] Call reforcast_figures[\code]

This will then run the macro when the workbook opens

Regards

Stephen

Mon 21 Jun 2010: Automatically marked as resolved.

 

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

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.