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 :)
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Is the procedure that your shape is linked to in a different workbook? The fact that it doesn't work the first time might indicate that the workbook wasn't open at the first click, but if the workbook containing the procedure is then opened, that would mean that any subsequent clicks would work fine. Just a thought.
 
Upvote 0
Is the procedure that your shape is linked to in a different workbook? The fact that it doesn't work the first time might indicate that the workbook wasn't open at the first click, but if the workbook containing the procedure is then opened, that would mean that any subsequent clicks would work fine. Just a thought.

Thanks for the reply :)

No the sub is in the same workbook stored in a module.
I've tried to place the sub on the specific sheet also.
The sub is also denoted public.
 
Upvote 0
Now I've also tried to include the name of the module as suggested in other threads, but still no effect.

Anyone has any suggestions? Or experienced a similar problem?

My main issue is that I cant see what changes between the opening of the sheet and the second time i try to run to macro.
If it works the second time, the path, security etc. must all be ok?
 
Upvote 0
Just a thought on the comment by Pete.

Is it possible to run the macro, without specifying the name of the workbook?

The current call is: NameOfWorkbook.xlsm!'NameOfModule.NameOfSub "parameter"'

I've tried to remove the name of the workbook, but excel seems to insert it by itself.

Is there any way to run the macro, just by calling the module and macro name?
 
Upvote 0
Can you post the actual code you are using to 'call' the macro?
 
Upvote 0
Pipeline_1.49.xlsm!'Pipeline.PrintPipeline "Denmark"'

The macro is "called" from a shape. Normally you would select the macro from the list available, but since the macro required parameters its not in the list. Hence I have to type it manually.

The strange part is that it works the second time i click the shape?!
 
Upvote 0
Why not use Application.Run in the Click event of the shape?

You can do that by selecting the shape, right clicking, selecting Assign Macro... and then click New instead of selecting a macro.

This is the kind of thing you should then see.
Code:
Sub RoundedRectangle1_Click()

End Sub

Try putting this in that sub.
Code:
Application.Run "Pipeline_1.49.xlsm!Pipeline.PrintPipeline", "Denmark"
 
Upvote 0
Pipeline_1.49.xlsm!'Pipeline.PrintPipeline "Denmark"'

The macro is "called" from a shape. Normally you would select the macro from the list available, but since the macro required parameters its not in the list. Hence I have to type it manually.

The strange part is that it works the second time i click the shape?!

Can you email the workbook?

Also, not sure about the Syntax of a macroname with spaces and double quotes...
 
Upvote 0
Thank you so much Norie. It worked perfectly :)
I have still no idea as to why is should work better, but it did!

I used this code where the sheet name is removed so I can change the name without changing the code:

Code:
Public Sub Pipeline_Click()
Application.Run "Pipeline.PrintPipeline", "Denmark"
End Sub

Where "Pipeline" is the name of the shape.

Thanks again for all suggestions and the help :)
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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