Trouble with an assign macro to a shape for exported file

atf32

Board Regular
Joined
Apr 13, 2011
Messages
157
Using Excel 2010, window 7

I recently used the Illustration toolbar (Shapes) to create a button and then assigned a macro to it. I did so because it provides more color options, etc. This works well in the workbook and looks great. And the called macro is in the module for the worksheet. However, part of the function of the workbook is to export a few of the tabs, including the one with my button and then rename the tab accordingly. My problem is that the button on the exported file does not work. I actually have to manually reassign the macro to the button to get it to work.

Can someone please confirm whether or not this is doable and if so provide a sample of how to do this?:confused:
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Something like this can assign a macro to a button
Code:
ActiveSheet.Buttons(1).OnAction = "Macro1"

If you can't modify the above to suit you needs:
-Can you show your code?
-Is there only one button on the sheet?
-What's the name of the macro and sheet name.
 
Last edited:
Upvote 0
I tried to modify your code, like you said. I used the following:

Code:
 Private Sub Worksheet_Activate()
    ActiveSheet.Shapes.Range(Array("BtnHide_SBTRows")) = "CALL_Code1"
End Sub [\Code]

Note: 1) "BtnHide_SBTRows" is the name of the shape that I am using as a button
        2) "CALL_Code1" is the called procedure that does something

Not sure, but I think that since the name of the worksheet changes during the export, that that becomes the disconnect of the assigned macro.  However, if I use a Form control button or ActiveX Button I don't have this issue.  Just can't use the options to make the button pop.
 
Last edited:
Upvote 0
Can you record a macro where you manually assign the macro to the shape and post that code?
 
Upvote 0
Sure:

Code:
 Sub attach_Code()' attach_Code Macro
'
    ActiveSheet.Shapes.Range(Array("BtnHide_SBTRows")).Select
    Selection.OnAction = "Sheet16.CALL_Code1"
End Sub [\Code]
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,915
Members
449,478
Latest member
Davenil

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