Cannot run the macro "macroname". The macro may not be available in this workbook or all macros may be disabled

tuetue

New Member
Joined
Apr 23, 2012
Messages
7
I have a workbook where I run a macro from a shape.
This is done by manually assigning the macro in the "assign macro" dialogue box.

The macro needs parameters, so the call is: NameOfWorkbook.xlsm!'NameOfMacro "parameter"'

When I open the workbook and tries to run the macro from the shape, I get the error message as in the title.
However If I press the shape again, it works just fine. No matter how many times I run the macro from this shape or other similar shapes afterwards there are no problems. It is only the first time i click it that there are problems.

I have tried to make the function public, but with no change in behaviour.
I have tried to change the security settings, but with no change in behaviour.

It should also be mentioned that I've read a lot of previous posts on this site and other with the same error, but none of the suggested solutions worked for me.


Any help or comments would be greatly appreciated

Thanks in advance :)
 
If this sub is in the same workbook as the one you are calling it from then you should be able to call it like this.
Code:
Public Sub Pipeline_Click()
    Call PrintPipeline("Denmark")
End Sub

Application.Run is only needed to run a sub that's in another workbook.

PS If the above doesn't work it could be to do with how the sub is declared and/or where it's located.
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Many of the posts show something like: NameOfWorkbook.xlsm!'NameOfMacro. If the NameOfWorkbook variable contains spaces, try either of these two solutions:
1) Remove the spaces from the value for NameOfWorkbook OR
2) For ONLY the Application.Run call, ALWAYS enclose the NameOfWorkbook within single quotes: Double Quote Single Quote Double Quote
Ex: NameOfWorkbook= "My Code Workbook.xlsm" (Note the embedded spaces)
MyCodeWorkbookName = "'" + NameOfWorkbook + "'"
MacroToRun = "!ModuleName.NameOfMacro" (Note the !)
RunProc = Application.Run(MyCodeWorkbookName + MacroToRun, <comma delimited parameter list>)
 
Upvote 0
Also, I thought I'd point this out, but if your Module name is the same as a procedure name, that will cause ambiguity and trigger this error message.

<comma delimited="" parameter="" list="">
i.e. Module Name
BoldACell


</comma>Public Sub BoldACell

End Sub

Attempting to call BoldACell would fail with this message.
 
Upvote 0
I realize that I'm 3 years late to the game, but I ran into this problem and found a solution that worked for me:

1) I encountered this error after I changed the name of the Macro in VBA
2) I reassigned the new name to the Command Button and IT WORKED

So, before you drive yourselves crazy - MAKE SURE THAT THE COMMAND BUTTON'S MACRO NAMES MATCHE THE SUB"S NAMES IN VBA!

Cheers,
-InterHOP
 
Upvote 0
This error message will also occur if a duplicate macro name exists in the workbook the macro is being called from.
 
Upvote 0
I have same problem in my workbook. I have tried every possible ways but nothing worked. Please give me your e-maid address & i'll send that file.
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

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