Excel runs a macro from the wrong workbook because it has the same name as the macro I'm trying to run

JohnTopham

New Member
Joined
Oct 23, 2017
Messages
1
Hi all,

I have two workbooks that are almost the same because they're from a master template workbook (I need both to be open at the same time). When I try to run a macro (Ex. Sub Calculate), it runs the Sub Calculate from the other workbook that is open. Is there a way to make sure it runs the one I want?

I want to avoid renaming every subroutine to be more specific.

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to the Board!

Yes, you can usually create a workbook reference dynamically "capture" the references of each workbook, and refer to which one you want to run the code on.
Of course, you will need to explain how to distinguish the two and determine which one it should be running against.

Note. You also NEVER want to use reserved words like "Calculate" as the name of your procedures, custom functions, or variables (reserved words are the names of existing Excel functions, properties, methods, etc). It can cause ambiguity, confusion, errors, and unexpected behavior. I often preface the name of my procedures and variables with the word "My..." to make sure I don't do that.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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