Excel VBA Immediate Window Question

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
When using the Immediate Window in the VBA editor, if running a macro from one of the open workbooks, is it possible to specify which workbook it runs from instead of having to click into the project containing the macro?

For example, say I have three open workbooks and each of them contains a macro in Module1 called "Test." I would run this in the Immediate Window by typing

Module1.Test

This runs the Test macro from whichever project I have selected in the Project Explorer pane. I'd like to know if it's possible to specify which project to run from instead so I don't have to keep clicking into the project containing the macro, something like

Workbook1.Module1.Test

Is this possible? This is a simplified example but it becomes cumbersome in more complex scenarios.

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
By using Application.Run and specifying the workbook Name:

Application.Run "'" & Workbooks(1).Name & "'!NameOfMacro"

where 1 is the index number of the open workbook.

If NameOfMacro occurs in more than 1 module in the workbook then specify the module name:

Application.Run "'" & Workbooks(1).Name & "'!Module1.NameOfMacro"
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top