Hi,
I am facing a problem and am unable to figure out the reason after loads of searching...
I have an ActiveX CommandButton on Sheet2 of by workbook that I want to modify (i.e. change font etc.) via VBA code. Sheet2 is named "All Transactions" and I want to make my code work without any modifications even if the sheet is renamed to something else.
The below code works:
...but the below code does not
Any suggestions on why the 2nd piece of code does not work or what I can do to fix my problem?
thanks,
~kg
I am facing a problem and am unable to figure out the reason after loads of searching...
I have an ActiveX CommandButton on Sheet2 of by workbook that I want to modify (i.e. change font etc.) via VBA code. Sheet2 is named "All Transactions" and I want to make my code work without any modifications even if the sheet is renamed to something else.
The below code works:
Code:
With ThisWorkbook.Sheets("All Transactions").CommandButton1
.ForeColor = colorBlue
.BackColor = colorYellow
.Font.Name = "Calibri"
.Font.Size = 12
.Caption = "Click to update data in" & vbNewLine & "Column K"
End With
...but the below code does not
Code:
Dim sht2 As Worksheet
Set sht2 = ThisWorkbook.Sheets(2)
With sht2.CommandButton1
.ForeColor = colorBlue
.BackColor = colorYellow
.Font.Name = "Calibri"
.Font.Size = 12
.Caption = "Click to update data in" & vbNewLine & "Column K"
End With
Any suggestions on why the 2nd piece of code does not work or what I can do to fix my problem?
thanks,
~kg