ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with Command Button (https://www.excelbanter.com/excel-programming/386960-help-command-button.html)

wf

Help with Command Button
 
How to define the properties for a command button so that it works in a
worksheet?

Thank you

Norman Jones

Help with Command Button
 
Hi W,

How to define the properties for a command button so that it works in a
worksheet?


Manually?
In design mode, right-click the CommandButton and select
'Properties' from the dropdown menu.

With VBA?

Try, something like:

'=============
Private Sub Worksheet_Activate()
With Me.CommandButton1
.BackColor = &H80000012
.ForeColor = &HFF&
End With
End Sub
'<<=============

This is worksheet event code and should be pasted into
the worksheets's code module (not a standard module
and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.

Alternatively, perhaps, in a standard module:
'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim oleObj As OLEObject

Set WB = Workbooks("MyBook.xls")
Set SH = WB.Sheets("Sheet1")
Set oleObj = SH.OLEObjects("CommandButton1")
With oleObj.Object
.ForeColor = &H80FFFF
.BackColor = &HFF&
End With
End Sub
'<<=============


---
Regards,
Norman





All times are GMT +1. The time now is 10:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com