C
chrisf84540
I use this macro to print all new incoming messages. I use Outlook
2002. Since the messages are html and contain images, this macro
displays then prints each message. This accomodates an Outlook 2002
requirement that incoming messages be displayed prior to printing.
Problem is, if messages arrive more frequently then, say, 1 minute, the
macro will just process one incoming message, but leave other incoming
messages unprocessed. Otherwise, it works great.
I don't want to have to increase the delay; right now it delays 15
seconds after displaying, and 15 seconds after printing; I guess that
is not enough time in some cases.
Often, we get the Outlook message, ""Items in this message are still
loading. Please wait a moment and then try again."
I need to force the macro to wait until each item is fully displayed
and printed prior to attempting to process another item. I also would
want to make sure that ALL unread items in the inbox are processed in
case one gets missed.
Thanks,
Chris
Here is the code, and it runs in the ThisOutlookSession module:
-----------------------------------------------------------------------
Option Explicit
Private WithEvents olInboxItems As Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate objects declared WithEvents
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Dim PauseTime, Start, Finish, TotalTime
If ISLIKE(Item.Subject, "Online Order*") = True Then
Item.Display
'here are your three choices about window state...
'Application.ActiveWindow.windowstate 0 = maximized
'Application.ActiveWindow.windowstate 1 = minimized
'Application.ActiveWindow.windowstate 2 = normalwindow
Application.ActiveWindow.WindowState = 1
'pause 5 seconds after display before printing to avoid message
'timer
'Dim PauseTime, Start, Finish, TotalTime
PauseTime = 15 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
Item.PrintOut
'timer
'Dim PauseTime, Start, Finish, TotalTime
PauseTime = 15 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
Item.Close (olSave)
Set Item = Nothing
End If
End Sub
2002. Since the messages are html and contain images, this macro
displays then prints each message. This accomodates an Outlook 2002
requirement that incoming messages be displayed prior to printing.
Problem is, if messages arrive more frequently then, say, 1 minute, the
macro will just process one incoming message, but leave other incoming
messages unprocessed. Otherwise, it works great.
I don't want to have to increase the delay; right now it delays 15
seconds after displaying, and 15 seconds after printing; I guess that
is not enough time in some cases.
Often, we get the Outlook message, ""Items in this message are still
loading. Please wait a moment and then try again."
I need to force the macro to wait until each item is fully displayed
and printed prior to attempting to process another item. I also would
want to make sure that ALL unread items in the inbox are processed in
case one gets missed.
Thanks,
Chris
Here is the code, and it runs in the ThisOutlookSession module:
-----------------------------------------------------------------------
Option Explicit
Private WithEvents olInboxItems As Items
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
' instantiate objects declared WithEvents
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Dim PauseTime, Start, Finish, TotalTime
If ISLIKE(Item.Subject, "Online Order*") = True Then
Item.Display
'here are your three choices about window state...
'Application.ActiveWindow.windowstate 0 = maximized
'Application.ActiveWindow.windowstate 1 = minimized
'Application.ActiveWindow.windowstate 2 = normalwindow
Application.ActiveWindow.WindowState = 1
'pause 5 seconds after display before printing to avoid message
'timer
'Dim PauseTime, Start, Finish, TotalTime
PauseTime = 15 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
Item.PrintOut
'timer
'Dim PauseTime, Start, Finish, TotalTime
PauseTime = 15 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
Item.Close (olSave)
Set Item = Nothing
End If
End Sub