有没有一种简单的方法可以更改VBA中ActiveX命令按钮的标题?

时间:2019-04-28 19:10:08

标签: excel vba

我发现这些其他问题here and here有点太高级了。我只需要一种简单的方法即可在运行VBA代码时更改ActiveX命令按钮“ CommandButton1”的标题。我敢肯定它可以比其他示例更简单吗?

2 个答案:

答案 0 :(得分:4)

对于不在工作表模块中运行的代码(Sheet1是工作表Code Name):

Sheet1.CommandButton1.Caption = "Text"

对于在工作表模块中运行的代码,不需要Sheet1.部分。

答案 1 :(得分:1)

我认为它不会比这更简单:

Sub test()
Dim sht As Worksheet
Set sht = ThisWorkbook.Worksheets("Name of your Worksheet") 'the worksheet in which the button is located
sht.OLEObjects("Name of your Command Button").Object.Caption = "test"
End Sub