Consulting

Results 1 to 3 of 3

Thread: Help with Inbox refresh and Autorun

  1. #1
    VBAX Newbie
    Joined
    Oct 2014
    Posts
    1
    Location

    Help with Inbox refresh and Autorun

    Hi,

    I'm new to Outlook VBA, but I've done some in Word and extensive Excel macros, as well as .NET development. We are running Outlook 2010.

    I get a number of validation emails (success/fail) from overnight jobs. Rather than reading each one every morning, I got the idea to build a macro to consolidate all the results into one email. This works well for the most part, but I have a couple of issues.

    1) The macro does not always automatically run each morning when I start Outlook. I have added a Private Sub Application_Startup routine in the 'This Outlook Session' folder, which calls my routine. When I launch Outlook, it works some days and other days it does not.

    2) When it does run, I've had an issue with it running before the Inbox is refreshed. So often, when my macro does run, many of my jobs show a status of 'Unknown' (from my code), because it can't find many of the emails. As soon as my macro runs, Outlook refreshes the inbox and the missing emails are loaded in. I tried putting a delay at the start of my macro, like the code at the bottom of this post, but this just seems to hold up all the Outlook processes for a minute, then my code runs and then the inbox is refreshed. I've tried to find VBA code that refreshes the inbox, but I haven't found any.

    Can anyone tell me why my macro only runs occasionally, and how to refresh my inbox using VBA?

    Thanks for your help!

    fCurrentTime = Now
    Do Until fCurrentTime + TimeValue("00:01:00") <= Now
      DoEvents
    Loop

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Quote Originally Posted by jwelsh View Post
    Can anyone tell me why my macro only runs occasionally, and how to refresh my inbox using VBA?
    There does not appear to be enough information to determine why your code does not run at startup. In any case, try ItemAdd or NewMailEx. Code runs only when items are received so there is no need to refresh.

    How to process incoming messages in Microsoft Outlook http://www.outlookcode.com/article.aspx?id=62
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    The following will Refresh the inbox(es)

    Dim olSycs As SyncObjects
    Dim j As Long
        Set olSycs = Session.SyncObjects
        For j = 1 To olSycs.Count
            olSycs.Item(j).Start
        Next j
    Cleanup:
        Set olSycs = Nothing
    However you may find it useful to process the messages as they arrive http://www.gmayor.com/extract_data_from_email.htm

    or after they have arrived - http://www.gmayor.com/extract_email_data_addin.htm
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •