Excel VBA Allow focus on another workbook

Josh Hazel
05-06-2008, 11:30 PM
Another question...

I have a loop running, which updates a new value in Cell A1 on Workbook 1 every second. I also have Workbook 2 open.

While the loop is running I am unable to click on another workbook in the taskbar, it simply stays on Wookbook 1. However, if I minimize Workbook 1 (the loop will still run) I am able to select Workbook 2 just fine.

How can I fix this problem, so I can click on Workbook 2 in the taskbar, and it will bring focus to Workbook 2, instead of Workbook 1?

Colin Legg
05-07-2008, 01:54 AM
Hi Josh,

I quickly set up a loop/timer using the application object's OnTime method and I had no trouble at all.

I saw your previous post and I'm suspecting that there's some 'dodgy' coding going on here. How about you post your code - the loop and the timer - so we can see what's going on? Are you using Windows Timers?

For your reference, there's a really good MVP article by Chip Pearson on using timers on his website here:
http://www.cpearson.com/excel/OnTime.aspx

Colin

Timbo
05-07-2008, 05:53 AM
A 'DoEvents' at the end of each loop cycle might help too! :)

Josh Hazel
05-08-2008, 09:46 PM
Hi Josh,

I quickly set up a loop/timer using the application object's OnTime method and I had no trouble at all.

I saw your previous post and I'm suspecting that there's some 'dodgy' coding going on here. How about you post your code - the loop and the timer - so we can see what's going on? Are you using Windows Timers?

Colin

Thanks for the reply... here is one of my subroutines running the timer. I attached the file in a zip too... Some of the code I put in there not fully understanding how it works, pulling from different websites - so as you mention, i may have misused something. Any additional comments/tips on anything else in there is accepted =)

Sub CountTimesheetLogIn()

CurrentCountContinue = True
intTrackLog = 1
Dim nametest As Boolean
nametest = Sheets("timer").chkLog1.Value
If Sheets("timer").chkLog1.Value = True And intLog1 = 0 And blnLog1 = False Then
CountTimesheetLog1
Else
End If

If CDate(Format(Now(), "hh:mm AM/PM")) > CDate(Format(LogIn, "hh:mm AM/PM")) Then
CountTimesheetBreak1Out
Else
Do Until CurrentCountContinue = False Or CDate(Format(Now(), "hh:mm AM/PM")) >= CDate(Format(LogIn, "hh:mm AM/PM")) Or blnStopFlag = True
DoEvents
ClockTime = Format(Now(), "hh:mm:ss AM/PM")
Loop
AppActivate "Microsoft Excel"
Call sndPlaySound32("c:\windows\media\chimes.WAV", 1)
'C:\WINDOWS\MEDIA\reminder.wav for outlook reminder sound
If CurrentCountContinue = False Then
Exit Sub
Else
Beep
Call sndPlaySound32("c:\windows\media\chimes.WAV", 1)
MsgBox "Log In Time is " & Format(LogIn, "hh:mm AM/PM")
Range("h17") = Format(Now(), "hh:mm AM/PM")
Range("g17") = Format(Now(), "hh:mm AM/PM")
Range("g24") = Format(DateAdd("n", 510, Range("g17")), "hh:mm AM/PM")
LogOut = Format(Range("g23"), "hh:mm AM/PM")

webOMD
End If
CountTimesheetBreak1Out
End If
blnStopFlag = False
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum