change color of command button problem

B

Bert

Earlier I posted a message about this, but thought the problem had to do
with a timer loop. When the suggestions for fixes didn't help, I (after
about 3 hours of changing things around) discovered the following.
First the code: (The button just clicked and previous button clicked are
supposed to turn red, then after two seconds turn gray. The problem is only
the previously clicked button turns red. )
Public Sub BadChoice()
Worksheets(2).OLEObjects.Item(FirstBtnNo).Object.BackColor = Red
Worksheets(2).OLEObjects.Item(BtnNo).Object.BackColor = Red
Application.Wait Now + TimeSerial(0, 0, 2)
Worksheets(2).OLEObjects.Item(BtnNo).Object.BackColor = Gray
Worksheets(2).OLEObjects.Item(FirstBtnNo).Object.BackColor = Gray
End Sub
Now the "rest of the story": This procedure may get called depending on the
user clicking correctly on "Yes" or "No" in either a UserForm or a Msgbox.
(I've tried both userform and msgbox--and both create the problem.) IF I
leave the Userform or Msgbox where it first appears on the screen, then
everything works fine, BUT if I move either the Msgbox or UserForm, the
"no-red" problem happens. (I'm moving it because I'd like to have the
Userform or Msgbox appear at a specific location over the spreadsheet.)
Any suggestions why this is happening and how to fix it?
Thanks.
Bert
 
B

Bob Phillips

Bert,

I couldn't get the red at all, but I got this to work

Public Sub BadChoice()

With Worksheets(2).OLEObjects

.Item(FirstBtnNo).Object.BackColor = red
.Item(BtnNo).Object.BackColor = red
Application.OnTime Now + TimeSerial(0, 0, 5), "ResetChoice"
End With
End Sub

Public Sub ResetChoice()
With Worksheets(2).OLEObjects

.Item(BtnNo).Object.BackColor = gray
.Item(FirstBtnNo).Object.BackColor = gray
End With
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
B

Bert

Bob:
That seemed to do the trick. Thanks

Bob Phillips said:
Bert,

I couldn't get the red at all, but I got this to work

Public Sub BadChoice()

With Worksheets(2).OLEObjects

.Item(FirstBtnNo).Object.BackColor = red
.Item(BtnNo).Object.BackColor = red
Application.OnTime Now + TimeSerial(0, 0, 5), "ResetChoice"
End With
End Sub

Public Sub ResetChoice()
With Worksheets(2).OLEObjects

.Item(BtnNo).Object.BackColor = gray
.Item(FirstBtnNo).Object.BackColor = gray
End With
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)
 

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