Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change BackColor of CommandButtons in Black by Macro

3 views
Skip to first unread message

K

unread,
Jan 19, 2009, 7:44:16 AM1/19/09
to
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

Rick Rothstein

unread,
Jan 19, 2009, 3:11:48 PM1/19/09
to
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)


"K" <kamra...@yahoo.co.uk> wrote in message
news:45f35af2-62ee-4a58...@w39g2000prb.googlegroups.com...

K

unread,
Jan 20, 2009, 3:43:34 AM1/20/09
to
On Jan 19, 8:11 pm, "Rick Rothstein"

<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> 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)
>
> "K" <kamranr1...@yahoo.co.uk> wrote in message

>
> news:45f35af2-62ee-4a58...@w39g2000prb.googlegroups.com...
>
>
>
> >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- Hide quoted text -
>
> - Show quoted text -

Thanks lot Rick. You are genious

0 new messages