View Full Version : Solved: Flashing command button
georgiboy
12-13-2008, 11:08 AM
How would i make something like my example below...
A) flash faster than one second per change
B) random colours instead of just two
Sub ColChange()
If Sheet1.CommandButton1.BackColor = vbBlue Then
Sheet1.CommandButton1.BackColor = vbRed
Else
Sheet1.CommandButton1.BackColor = vbBlue
End If
If Sheet1.CommandButton1.BackColor = vbBlue Then
Sheet1.CommandButton1.ForeColor = vbRed
Else
Sheet1.CommandButton1.ForeColor = vbBlue
End If
appTime = Now() + TimeValue("00:00:01")
Application.OnTime appTime, "ColChange"
End Sub
Thanks in advance
Bob Phillips
12-13-2008, 12:04 PM
Try this
georgiboy
12-13-2008, 12:42 PM
Thanks Bob that has given me alot to think about, i can see that nearly all that code is needed to run it. I think i have seen this before, is it from your interactive clock project?.
What is the best way to set "ncolour" to just two/three specific colours?
My guess would be "if button.forecolor = 3 then ncolour = 2 and so on, but i am all too atracted to the if statement i seem to love it for some reason.
Cheers
George
Bob Phillips
12-13-2008, 04:06 PM
Yes, that came from the interactive clock as you say. They both use the same fundamental, using callbacks to invoke the windows timer. I wrote the clock project some time ago in VB, and then adapted it in VBA before I understood OnTime. The clock really doesn't need the windows timer, OnTime is good enough as it is unlikey that precision of less than one second is needed. But you wanted less than one second precision, so it is perfect for that.
If you wanted 2 or 3 colours only, I would just use an array and a counter, something like this
Dim aryBackColours As Variant
Dim aryForeColours As Variant
Dim iColour As Long
aryBackColours = Array(8421504, 16763904, 8388736)
aryForeColours = Array(vbYellow, vbBlue, vbRed)
iColour = iColour + 1
If iColour > 3 Then iColour = 1
Sheet1.CommandButton1.BackColor = aryBackColours(iColour)
Sheet1.CommandButton1.ForeColor = aryForeColours(iColour)
georgiboy
12-14-2008, 01:29 AM
Thanks alot Bob, i can now make some of my spreadsheets light up like a christmas tree.:xmas:
Cheers
George
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.