View Full Version : Solved: Auto-close Outlook
mdmackillop
09-10-2007, 07:43 AM
We have backup problems if users don't close Outlook at night. Can this be automated with a macro (to be installed on each pc), to run at 9pm if Outlook is still open?
Regards
MD
mvidas
09-10-2007, 12:34 PM
Hey Malcolm,
You could do this using API timers, since outlook doesn't have an OnTime method or anything. I'd recommend using an add-in instead of just plain macros, it could prevent the user from changing something in the code and crashing outlook.
Just to give you some pseudocode to show what I mean, you could have code that looks likePrivate Sub Application_Startup()
If Time < TimeValue("9:00:00 pm") And Time > TimeValue("5:00:00 am") Then
'set timer to call TimerTrigger at 9pm
End If
End Sub
Private Sub Application_Quit()
'turn off timer
End Sub
Sub TimerTrigger()
Application.Quit
End SubWould that be something you're interested in trying? I could give you the code to use it via VBA first and if it works like you want I could help you make an add-in
mvidas
09-10-2007, 12:57 PM
Just to give you the code to test it..
ThisOutlookSession code:Option Explicit
Private Sub Application_Startup()
If Time < TimeValue(AutoCloseTime) Then StartAutoCloseTimer
End Sub
Private Sub Application_Quit()
StopAutoCloseTimer
End Sub
Standard module code:Option Explicit
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal _
nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal _
nIDEvent As Long) As Long
Public pbnIDEvent As Long
Public Const AutoCloseTime As String = "9:00:00 pm"
Sub TimerTrigger(ByVal hwnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, _
ByVal dwTimer As Long)
KillTimer 0&, nIDEvent
DoEvents
Application.Quit
End Sub
Sub StartAutoCloseTimer()
Dim TimeTilAutoClose As Long
TimeTilAutoClose = CLng((TimeValue(AutoCloseTime) - Time()) * 24 * 60 * 60 * 1000)
If TimeTilAutoClose > 1000 Then 'make sure theres at least a second to trigger it
pbnIDEvent = SetTimer(0&, 0&, TimeTilAutoClose&, AddressOf TimerTrigger)
End If
End Sub
Sub StopAutoCloseTimer()
If pbnIDEvent <> 0 Then KillTimer 0&, pbnIDEvent
End Sub
Note that I haven't actually tested that myself, though it should work..?
mdmackillop
09-10-2007, 01:56 PM
Thanks Matt
I've tried it here and it works a treat. An add-in is a good idea. I can keep it on the server for ease of maintenance.
TrippyTom
09-10-2007, 03:11 PM
What happens if someone works late (overtime) and works past 9pm? Wouldn't you get an angry voice mail about someone's outlook closing on them? :eek:
Or maybe you're lucky (like me) and the blame will go to someone else like the real I.T. guy - whenever anything goes wrong with people's PCs, he's the one that gets dirty looks.
mdmackillop
09-11-2007, 01:09 AM
Well it will probably be later, just before the backup is scheduled, but they'll be told it will happen.
mvidas
09-11-2007, 07:11 AM
You could always pop up a form an hour before backup .. "Outlook needs to close at XX:XX PM to prepare for backup. Click cancel to work for a little longer" and have that form have a 30-60 second warning countdown timer. If cancel is clicked - Tell the user they have YY minutes before forced shutdown. If no response, shut it down. Sounds a little friendlier at least.
Malcolm - If you are going to be making an add-in, you wouldn't need to use the API timers as VB has a timer object, would probably make it a bit easier. Probably uses the APIs, just wrapped for ease of use.
In either case, do you want help with the add-in? I'm guessing you have visual studio (part of MSDN), though I'd be able to help during the evening if need be.
mdmackillop
09-11-2007, 11:08 AM
I had a look at add-ins and I'm not sure it's worth the trouble. No-one in my offices has heard of Alt F11, so I don't have problems with interference.
I'll mark this as solved.
Thanks Matt
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.