How to fix if macro is trying to call sub from another workbook

dmadhup

Board Regular
Joined
Feb 21, 2018
Messages
146
Office Version
  1. 365
Hi,
I open two or more workbooks on my computer. I am using the syntax:

Call macro_name

to call another macro in a module from the same workbook I am in. But sometimes it tries to call from another workbook where not found and throw the error like:

Method name of method not found.

Any help is appreciated.

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If you want to call macro_name from another workbook (for this example say its My Workbook.xlsm) and both workbooks are open, try this syntax from the calling workbook"

Code:
Application.Run "'My Workbook.xlsm'!macro_name"
Be sure to use the combination of single and double quotation marks as shown.

Joe,

I like what is done here, but is there a way to allow the workbook name to be a variable being called in? I am working on something similar to issue in this thread, just a touch off.
Thanks if you can
 
Upvote 0
Joe,

I like what is done here, but is there a way to allow the workbook name to be a variable being called in? I am working on something similar to issue in this thread, just a touch off.
Thanks if you can
Not sure I understand what you mean by "to be a variable being called in". Do you want to assign a variable to the called workbook? If so, you can try this (untested by me):

Code:
Dim WB as variant
set WB = Workbooks("My Workbook.xlsm")
Application.Run "'" & WB.Name & "'!macro_name"
 
Last edited:
Upvote 0
What about this way, so that you can change the workbook name and your program won't get affected.


Application.Run "'" & ThisWorkbook.Name & "'!macro_name"
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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