Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / April 2005

Tip: Looking for answers? Try searching our database.

Force Macro to Wait Until New Message Displayed and Printed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
chrisf84540@yahoo.com - 08 Apr 2005 21:50 GMT
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
Michael Bauer - 11 Apr 2005 07:21 GMT
Hi Chris,

in general I´d say, you need a control, that fires an event if the
document is fully loaded. In VB I´d probably use the DHTMLEdit control,
but AFAIK you can´t use it on a MSForms Formular.

Please search in your available components, maybe there is the
"Microsoft Webbrowser" e.g. You could then save the mails as HTML files,
load it into the control and print.

Signature

Viele Grüße
Michael Bauer - MVP Outlook

> I use this macro to print all new incoming messages. I use Outlook
> 2002. Since the messages are html and contain images, this macro
[quoted text clipped - 67 lines]
> End If
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.