问题
I am not sure, even if this is possible. I would like to change the named of the button when clicked.
I have Active X button that will enable cells on the sheet when clicked. Name of the button "Enable Sheet".
Once he enables, he should see a button "Disable Sheet". Please advise.
回答1:
assuming your button is named after "CommandButton1":
Private Sub CommandButton1_Click()
With Me.OLEObjects("CommandButton1").Object
.Caption = IIf(.Caption = "Enable Sheet", "Disable Sheet", "Enable Sheet")
End With
End Sub
edited after OP's comments
Private Sub CommandButton1_Click()
With Me.OLEObjects("CommandButton1").Object
.Caption = IIf(.Caption = "Enable", "Disable", "Enable")
Range("E13:E14").Locked = .Caption = "Enable"
End With
End Sub
回答2:
In the code that you can attach to the ActiveX object, you can try something like this:
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Enable"
End Sub
In general, for ActiveX Objects, you can change the displayed text using the .Caption
property.
来源:https://stackoverflow.com/questions/40356317/vba-to-change-the-name-of-the-activex-button