Calling a Macro from another workbook

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This is straight from the VBA guide:

If you give the same name to two different procedures in two different projects, you must specify a project name when you call that procedure. For example, the following procedure calls the Main procedure in the MyModule module in the MyProject.vbp project.
Code:
Sub Main()
	[MyProject.vbp].[MyModule].Main
End Sub
 
Upvote 0
Application.Run "MacroBook!MacroName"

I have tried this over and over again and everytime it tells me

"Can not run the macro 'Weekly Shrinkage Tool.xlsm!NewWeek'. The macro may not be available is this workbook or all macros may be disabled."

I have tried all sorts of versions of the line

Application.Run "MacroBook!MacroName"

including using a variable for the file name which I can't get to work at all

but here are some ways I have typed it

Application.Run "Weekly Shrinkage Tool.xlsm!NewWeek"
Application.Run "Weekly Shrinkage Tool.xlsm!NewWeek()"
Application.Run "Weekly Shrinkage Tool.xlsm!Public Sub NewWeek()"
Application.Run "Weekly Shrinkage Tool!NewWeek"

Am I missing something like a simple sintax error?
 
Upvote 0
Found the solution :)

if you try to run a macro from a workbook that contains spaces you must enclose them with apostrophe, such as

Code:
Application.Run ("'Analytics macro S17.xlsm'!getdata")
 
Upvote 0
I am trying to do the same thing and continue to get the error "Cannot run the macro 'DPUSetup'. The macro may not be available in this workbook or all macros may be disabled."

I have checked and rechecked my macro security settings, there are no other macros, procedures, etc. with any duplicate names, and I have done this before on a different computer and it has worked perfectly. I just want one wb where all my macros live and want to run them all off that wb by selecting a macro icon on my quick access toolbar regardless of the actual wb that I am editing. Also, regarding the answer above, this macro in particular is coming from a brand new wb every day, so I don't want to build an application.run macro in that new wb just to run one macro every day. That doesnt make sense.

Please help!
 
Upvote 0
If the name of the workbook is dynamically assigned as a variable you can use this code

Application.Run ("'" & workbookname & "'!macroname")
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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