VBA to change the name of the Activex button

ⅰ亾dé卋堺 提交于 2020-01-17 05:43:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!