-1

I have found these other questions here and here which were a little too advanced. I just need a simple way to change the caption of an ActiveX command button "CommandButton1" when running a VBA code. I'm pretty sure it can be done way simpler than the other examples?

WoeIs
  • 1,083
  • 1
  • 15
  • 25

2 Answers2

5

For code not running in the sheet module ( Sheet1 is the sheet Code Name ) :

Sheet1.CommandButton1.Caption = "Text"

For code running in the sheet module, the Sheet1. part is not needed.

Slai
  • 22,144
  • 5
  • 45
  • 53
1

I don't think it can get much simpler than this:

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
Stavros Jon
  • 1,695
  • 2
  • 7
  • 17