Change BackColor of CommandButtons in Black by Macro

K

K

I have 10 ActiveX Control CommandButtons on my Sheet. I want macro in
ActiveX Control CommandButton11 that when I click button then all
CommandButtons 1 to 10 should get BackColor in Black and also what
should be code that when I click button then only CommandButtons 1 to
4 and 6 to 8 get BackColor in Black. Please can any friend can help
 
R

Rick Rothstein

Give this Click event code for CommandButton11 a try...

Private Sub CommandButton11_Click()
Dim X As Long
With Worksheets("Sheet3")
For X = 1 To 10
If X <> 5 Then
.OLEObjects("CommandButton" & X).Object.BackColor = vbBlack
End If
Next
End With
End Sub

Note: If you want to change all the buttons BackColor, then just remove the
If..Then and End..If statements. If you want to exclude other buttons for
being changed to black, just Or them into the If..Then list along with the
X<>5 exclusion.
 
K

K

Give this Click event code for CommandButton11 a try...

Private Sub CommandButton11_Click()
  Dim X As Long
  With Worksheets("Sheet3")
    For X = 1 To 10
      If X <> 5 Then
        .OLEObjects("CommandButton" & X).Object.BackColor = vbBlack
      End If
    Next
  End With
End Sub

Note: If you want to change all the buttons BackColor, then just remove the
If..Then and End..If statements. If you want to exclude other buttons for
being changed to black, just Or them into the If..Then list along with the
X<>5 exclusion.

--
Rick (MVP - Excel)






- Show quoted text -

Thanks lot Rick. You are genious
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top