Timer works but can't view another workbook

Rick93636

New Member
Joined
Jan 11, 2014
Messages
24
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:

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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I didn't try your code but can you add the following line (in red color) to your code;

Code:
Sub StartBlinking()
   [COLOR=#ff0000][B] DoEvents[/B][/COLOR]
    'Rest of your code ...
    '.....
 
Last edited:
Upvote 0
Thanks for the suggestion, Haluk.
DoEvents had no effect. It appears that if a timer is running then the workbook & worksheet that the timer macro refers to must be active.
If I need to view another workbook I'll just hit the Windows button & type EXC enter to open a separate Excel session.

Thanks again,

Rick
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top