PDA

View Full Version : Help with Inbox refresh and Autorun



jwelsh
10-09-2014, 04:39 AM
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

skatonni
10-10-2014, 12:38 PM
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

gmayor
10-11-2014, 07:28 AM
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 (http://www.gmayor.com/extract_email_data_addin.htm)