Hi
This will help in case you have multiple Objects..
Sub CB_COLOR_CHANGE()
Dim cbutton As MSForms.CommandButton
Dim oleObj As OLEObject
For Each oleObj In ActiveSheet.OLEObjects
If TypeOf oleObj.Object Is MSForms.CommandButton Then
Set cbutton = oleObj.Object
With cbutton
If oleObj.Name = "CommandButton1" Then
.BackColor = RGB(255, 0, 0) '&HFFFFC0
End If
If oleObj.Name = "CommandButton2" Then
.BackColor = &HFFFFC0 'RGB(400, 0, 0) '
End If
End With
End If
Next
End Sub
Cheers!!
On Thu, May 8, 2014 at 5:20 PM, Vaibhav Joshi <[email protected]> wrote:
> Try this:::
>
> Sub CB_COLOR_CHANGE()
> Dim cbutton As MSForms.CommandButton
> Dim oleObj As OLEObject
> For Each oleObj In ActiveSheet.OLEObjects
> If TypeOf oleObj.Object Is MSForms.CommandButton Then
> Set cbutton = oleObj.Object
> Exit For
> End If
> Next
> cbutton.BackColor = RGB(255, 0, 0) '&HFFFFC0
> End Sub
>
>
> Cheers!!
>
>
> On Thu, May 8, 2014 at 2:19 PM, Karsten Vestertjele
> <[email protected]>wrote:
>
>> I've made a sheet with some buttons on. They need to change color when a
>> sub is active. Like this:
>>
>> *Private Sub ChangeColor()*
>> CommandButton2.BackColor = RGB(255, 0, 0)
>> CommandButton2.Enabled = False
>> Sheet1.Activate
>> *End Sub*
>>
>> But nothing happens.. I can change the color if the code is put in the
>> button's "on click" sub but not from another sub..
>>
>> Some scope problem or?
>>
>> --
>> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
>> =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
>> https://www.facebook.com/discussexcel
>>
>> FORUM RULES
>>
>> 1) Use concise, accurate thread titles. Poor thread titles, like Please
>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
>> will not get quick attention or may not be answered.
>> 2) Don't post a question in the thread of another member.
>> 3) Don't post questions regarding breaking or bypassing any security
>> measure.
>> 4) Acknowledge the responses you receive, good or bad.
>> 5) Jobs posting is not allowed.
>> 6) Sharing copyrighted material and their links is not allowed.
>>
>> NOTE : Don't ever post confidential data in a workbook. Forum owners and
>> members are not responsible for any loss.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "MS EXCEL AND VBA MACROS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/excel-macros.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
https://www.facebook.com/discussexcel
FORUM RULES
1) Use concise, accurate thread titles. Poor thread titles, like Please Help,
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
NOTE : Don't ever post confidential data in a workbook. Forum owners and
members are not responsible for any loss.
---
You received this message because you are subscribed to the Google Groups "MS
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.