Error Trying To Remove Macro Assignment to Shapes

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code which I am using to rid of the respective macros assigned to 11 different shapes on my worksheet. Each shape is named wthr_btn_# where # is a value between 1 and 11.

Rich (BB code):
    With ws_gui    
       For wbtn = 1 To 11
            swbtn = "wthr_btn_" & wbtn
            With .Shapes(swbtn)
                .OnAction = "" 'removes macro assignments
                .Fill.ForeColor.RGB = vbWhite
                .Line.Weight = 0.25
                .Line.ForeColor.RGB = vbBlack
            End With
        Next wbtn
     End With

The line in red is stopping the code with an error. "Application defined or object defined error".
swbtn = "wthr_btn_1"
wthr_btn_1 has a macro assigned to it: "pkdata_3.xlsm!btn_mclr"

Suggestions to overcome the error?
 
If you grouped the shape and the textbox and then assigned name to it, it should be no problem with the code.
If you created the shape, assigned macro to it and then created a textbox and grouped it with the shape. It would not work.
 
Upvote 0
Solution

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
So, I believe I have solved the issue. Using the selection pane, I selected all the components of each grouped object and removed the macros I had assigned using the right mouse button context menu. None of the 11 buttons have macros. I have then gave each grouping a unique and sequential name. btn_grp_1 through btn_grp_11.

I have adapted my code to this as a result.

Code:
    With ws_gui 'worksheet was previously set publically in another code
        For wbtn = 1 To 11
            swbtn = "btn_grp_" & wbtn
            Set shp = .Shapes(swbtn)
            With shp
                .OnAction = "" 'removes macro assignments
            End With
        Next wbtn
        For wbtn = 1 To 11
            swbtn = "wthr_btn_" & wbtn
            Set shp = .Shapes(swbtn)
            With shp
                .Fill.ForeColor.RGB = vbWhite
                .Line.Weight = 0.25
                .Line.ForeColor.RGB = vbBlack
            End With
        Next wbtn
     End With

No error, but not sure if it will work when macros are assigned.

Not sure if I should start another post, but now I have problems assigning the buttons macros. Buttons are assigned macros only after the user has completed specific data entry. Once that data has been entered, the buttons become "enabled" with the assignment of respective macros.

Here is the code that I am using to assign the macros. The line in red is giving me an "Application defined or object defined error". Perhaps I can't assign a macro to a grouped shape?

Rich (BB code):
     If Not Intersect(Target, Range("$F$7")) Is Nothing Then
        mbevents = False
        Unprotect
        'Range("Y4") = sZone
        Range("I7:J7").Locked = False
        With ws_gui
            .Shapes("btn_grp_1").OnAction = "'" & ActiveWorkbook.Name & "!btn_mclr"
            .Shapes("btn_grp_2").OnAction = "'" & ActiveWorkbook.Name & "!btn_ovc"
            .Shapes("btn_grp_3").OnAction = "'" & ActiveWorkbook.Name & "!btn_mcl"
            .Shapes("btn_grp_4").OnAction = "'" & ActiveWorkbook.Name & "!btn_flr"
            .Shapes("btn_grp_5").OnAction = "'" & ActiveWorkbook.Name & "!btn_sql"
            .Shapes("btn_grp_6").OnAction = "'" & ActiveWorkbook.Name & "!btn_snw"
            .Shapes("btn_grp_7").OnAction = "'" & ActiveWorkbook.Name & "!btn_mxd"
            .Shapes("btn_grp_8").OnAction = "'" & ActiveWorkbook.Name & "!btn_rain"
            .Shapes("btn_grp_9").OnAction = "'" & ActiveWorkbook.Name & "!btn_fzr"
            .Shapes("btn_grp_10").OnAction = "'" & ActiveWorkbook.Name & "!btn_wnd"
            .Shapes("btn_grp_11").OnAction = "'" & ActiveWorkbook.Name & "!btn_clr"
        End With
        Range("I7").Select
        Protect
        mbevents = True
    End If
 
Upvote 0
Instead of Activeworkbook.Name, try:

VBA Code:
Application.ActiveWorkbook.Name
 
Upvote 0
I tried your code in Post #7. It worked as I tested it. My conclusion was like in Post #11
 
Upvote 0
Instead of Activeworkbook.Name, try:

VBA Code:
Application.ActiveWorkbook.Name
Sadly, this didn't work either. I'm not getting very far fast with this project lol.
 
Upvote 0
This didn't either ...
Code:
.Shapes("btn_grp_1").OnAction = "!btn_mclr"
 
Upvote 0
Sorry - I completely missed it - you don't have a closing apostrophe after the workbook name. So:
VBA Code:
.Shapes("btn_grp_1").OnAction = "'" & ActiveWorkbook.Name & "'!btn_mclr"
 
Upvote 0
Ah! Nice. Thanks Dan, that was it. Very easy to overlook that! I'd love to give you a check mark, but I"ve already left that with Zot who contributed to providing the solution to the original problem. Butr consider a check for finding the solution to the collateral problem.
 
Upvote 0
Shucks... and I was one checkmark off being awarded that sports car...
LOL - that's completely fine... unless of course there is some kind of award being handed out, and I just didn't the forum FAQ properly! :unsure:

Glad it's working for you - Happy Friday everyone - have good weekend.
 
Upvote 0
Shucks... and I was one checkmark off being awarded that sports car...
LOL - that's completely fine... unless of course there is some kind of award being handed out, and I just didn't the forum FAQ properly! :unsure:

Glad it's working for you - Happy Friday everyone - have good weekend.
If you watch close enough, there is certainty I'll be back with a new problem. Lots of opportunity to earn checkmarks!! Promise. :-)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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