C-Love511
C-Love511

Reputation: 358

Removing Macro from Shape Programmatically

I have several "Buttons" that change dynamically with the content of the sheet. I just need to figure out 1 line of code to get it working properly (Line 3):

Public Sub ClearMacro(shapename As String)
    On Error Resume Next
    ActiveSheet.Shapes(shapename).OnAction = Nothing
End Sub

I want to completely remove the macro from the shape, but keep the shape. Anything I can do differently to make this work?

Upvotes: 0

Views: 2981

Answers (1)

user6432984
user6432984

Reputation:

Use Set and Nothing on objects. OnAction accepts a string value, use .OnAction = "" instead.

Public Sub ClearMacro(shapename As String)
    On Error Resume Next
    ActiveSheet.Shapes(shapename).OnAction = ""
End Sub

Upvotes: 2

Related Questions