This VBA demo illustrates how to display a prompt window to warning user that there are any items stuck in Outbox for a long time.
This is a frequently asked question by users in the TechNet forum. For example,
Import the two files (basOutboxMonitor.bas & clsOutboxMonitor.cls).
Step1. Press Alt+F11 to open the VBE in Outlook.
Step2. Select these two files and drag them to the Project Explorer (Press Ctrl+R if you cannot see it) or via File >> Import File... (Ctrl+M).
Begin to monitor Outbox.
Step3. Go back to Outlook UI, and then press Alt+F8 to open the Macros window.
Step4. Select "MonitorOutbox" in the names list, and then click the Run button.
Stop monitoring Outbox.
Step5. Close the Alert window first if it is displayed, and then run "DonotMonitorOutbox" in the Macros window.
Note:
1. Please make sure that macros are enabled in Outlook.
For Outlook 2010:
File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings >> Enable all macros >> OK >> OK >> Restart Outlook
For Outlook 2007:
Tools >> Macro >> Security... >> Macro >> Security >> No security check for macros >> OK >> Restart Outlook
For Outlook 2003:
Tools >> Macro >> Security... >> Macro >> Security >> Low >> OK >> Restart Outlook
2. If you want to begin to monitor Outbox automatically when Outlook runs, please paste the following code to ThisOutlookSession (refer to Step1).
Private Sub Application_Startup()
MonitorOutbox
End Sub
3. To change the stuck time in "basOutboxMonitor.bas":
' ///////////////////
' Stuck time.
' Unit: Minutes
' \\\\\\\\\\\\\\\\\\\
Private Const stuckTime As Integer = 30
4. To change the monitoring time in "basOutboxMonitor.bas":
' ///////////////////
' Monitoring time.
' Unit: Milliseconds
' \\\\\\\\\\\\\\\\\\\
Private Const monitoringTime As Long = 10000
5. The alert window is just like below:
The "Yes" button is for openning Outbox to check while the "No" button is for doing nothing (it will continue to monitor Outbox after you click any one of these two buttons).
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
' ##################################################
' Display a window dialog using Windows Script Host.
' ##################################################
Private Function SetAlertDialog(ByVal strText As String, _
Optional ByVal nSeconds As Long = 0, _
Optional strTitle As String, _
Optional ByVal dlgStyle As VbMsgBoxStyle) As VbMsgBoxResult
Dim objWsh As Object
Dim mbxResult As VbMsgBoxResult
Set objWsh = CreateObject("WScript.Shell")
mbxResult = objWsh.Popup(strText, nSeconds, strTitle, dlgStyle)
SetAlertDialog = mbxResult
Set objWsh = Nothing
End Function
' ################################################## ' Display a window dialog using Windows Script Host. ' ################################################## Private Function SetAlertDialog(ByVal strText As String, _ Optional ByVal nSeconds As Long = 0, _ Optional strTitle As String, _ Optional ByVal dlgStyle As VbMsgBoxStyle) As VbMsgBoxResult Dim objWsh As Object Dim mbxResult As VbMsgBoxResult Set objWsh = CreateObject("WScript.Shell") mbxResult = objWsh.Popup(strText, nSeconds, strTitle, dlgStyle) SetAlertDialog = mbxResult Set objWsh = Nothing End Function
Related forum threads: