Shape Onaction macro not found on first call

JSmithCol

New Member
Joined
Feb 9, 2015
Messages
3
I have a really weird one with a Shape that has it's onaction set to a macro. I have a shape where the parameter I want to use is stored in the AlternativeText of the shape. the line below is setting the OnAction command to call a macro named "getApplicationTab" passing the alternativetext as a paramater.

sh.OnAction = "'getApplicationTab """ & sh.AlternativeText & """'"

This code works perfectly except for the first time it is invoked when you open the workbook. When I first open the workbook and click on the shape I get the error Cannot run the macro "getApplicationTab "Online Banking"". The macro may not be available in this workbook or all macros may be disabled.

The funny this is when I click the shape a second time it works perfectly and continues to work.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Unfortunately, since this is undocumented syntax anyway, it's extremely hard to classify any behaviour as a bug. (For example, if you try and use it in an .xlsb file, you will have real problems)

Anyway, given that you are using a property of the shape as the parameter, why don't you just have the called macro read that directly rather than passing it as an argument?
 
Upvote 0
Unfortunately, since this is undocumented syntax anyway, it's extremely hard to classify any behaviour as a bug. (For example, if you try and use it in an .xlsb file, you will have real problems)

Anyway, given that you are using a property of the shape as the parameter, why don't you just have the called macro read that directly rather than passing it as an argument?


I would be fine with that. I have multiple shapes on the sheet with the same Macro assigned. How do you determine which shape was clicked on when the macro gets invoked?
 
Upvote 0
You'd use something like:
Code:
Dim sParameter as String
sParameter = Activesheet.Shapes(Application.Caller).AlternativeText
 
Upvote 0
Glad to help - welcome to the forum too! :)
 
Upvote 0

Forum statistics

Threads
1,216,979
Messages
6,133,848
Members
449,839
Latest member
adam234432

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