Hello-
I have code to run a timer to make cells blink and make beep sound if certain range values are met. It works great. But, if I open another workbook it goes to the background when the timer runs. So I can't view another workbook when the timer is running. If I turn the timer off then I can view other workbooks like normal.
I suspect my code is making my main workbook active and selects it when the timer runs. Any suggestions? Here's the code:
I have code to run a timer to make cells blink and make beep sound if certain range values are met. It works great. But, if I open another workbook it goes to the background when the timer runs. So I can't view another workbook when the timer is running. If I turn the timer off then I can view other workbooks like normal.
I suspect my code is making my main workbook active and selects it when the timer runs. Any suggestions? Here's the code:
Code:
Option Explicit
Public NextBlink As Double
'The cell that you want to blink
Public Const xBlinkCell As String = "FOC_Main!A3,A5,A7,A9,A11,A13,A15"
Public Const yBlinkCell As String = "FOC_Main!A4,A6,A8,A10,A12,A14"
Public Const BlinkCell As String = "FOC_Main!A3:A15"
'Start blinking
Sub StartBlinking()
If Range("FOC_Main!B37").Value = 1 Then
BeepNow
'If Range(BlinkCell).Interior.ColorIndex = 3 Then
'Range(BlinkCell).Interior.ColorIndex = 6
'Else
'Range(BlinkCell).Interior.ColorIndex = 3
'End If
If Range(xBlinkCell).Interior.ColorIndex = 6 Then
Range(xBlinkCell).Interior.ColorIndex = 3
Else
Range(xBlinkCell).Interior.ColorIndex = 6
End If
If Range(yBlinkCell).Interior.ColorIndex = 3 Then
Range(yBlinkCell).Interior.ColorIndex = 6
Else
Range(yBlinkCell).Interior.ColorIndex = 3
End If
End If
If Range("FOC_Main!B37").Value = 0 Then
Range("FOC_Main!A3:A15").Interior.ColorIndex = 16
End If
'Wait 2 seconds before changing the color again
NextBlink = Now + TimeSerial(0, 0, 2)
Application.OnTime NextBlink, "StartBlinking", , True
End Sub
'Stop blinking
Sub StopBlinking()
'Set color to gray
Range("FOC_Main!A3:A15").Interior.ColorIndex = 16
On Error Resume Next
Application.OnTime NextBlink, "StartBlinking", , False
Err.Clear
End Sub
Function BeepNow()
If Range("FOC_Main!D39").Value > 1 And Range("FOC_Main!D39").Value < 5 _
Or Range("FOC_Main!D39").Value > 31 And Range("FOC_Main!D39").Value < 39 Then
beep
End If
Exit Function
End Function