Because I tend to not notice new email notifications I developed a VBA macro that automatically displays newly arrived email. This works great for the default account but doesn't seem to work for a non-default account. Let me explain. I use my personal Outlook for both my own email and also for gmail and work. I'm having trouble getting the macro to work with my work email.
Here's how the macro works:
At the top of the file I define various variables.
Private WithEvents ItemsDisplay As Outlook.Items
Private WithEvents ItemsAutoDisplaySW as Outlook.Items
When Outlook first starts it calls Application_Startup() so I leverage this to register the new email event.
I had problems working out the syntax to specify the account I'd added to connect to my business email and ended up just iterating across all of the accounts until one was found with the right display name. Having found the account an attempt was made to find the Inbox. I was having trouble with that, too, and just guessed that GetDefaultFolder(olFolderInbox) would find it for me but I don't think it did.
Private Sub Application_Startup()
Set ItemsAutoDisplayMain = Application.Session.GetDefaultFolder(olFolderInbox).Items
' Find the SpectraWAVE account.
' Search the non-default accounts for my work account.
For I = 1 To Application.Session.Accounts.Count
If Application.Session.Accounts.Item(I).DisplayName = "rhaggard@workemail.com" Then
Set ItemsAutoDisplaySW = Application.Session.Accounts.Item(I).Session.GetDefaultFolder(olFolderInbox).Items
set I = Application.Session.Accounts.Count + 1
End If
Next I
End Sub
And, of course, we need the actual event handlers themselves.
Private Sub ItemsAutoDisplay_ItemAdd(ByVal Item As Object)
On Error Resume Next
Item.Display
End Sub
Private Sub ItemsAutoDisplaySW_ItemAdd(ByVal Item As Object)
On Error Resume Next
Item.Display
End Sub
Note: Since both of these event handlers do exactly the same thing I wonder it I could dispense with ItemsAutoDisplaySW and use ItemsAutoDisplay for all autodisplay accounts?
Anyway, anyone spot what I've done wrong to break the auto display for my non-default work account?
====
Rick
Here's how the macro works:
At the top of the file I define various variables.
Private WithEvents ItemsDisplay As Outlook.Items
Private WithEvents ItemsAutoDisplaySW as Outlook.Items
When Outlook first starts it calls Application_Startup() so I leverage this to register the new email event.
I had problems working out the syntax to specify the account I'd added to connect to my business email and ended up just iterating across all of the accounts until one was found with the right display name. Having found the account an attempt was made to find the Inbox. I was having trouble with that, too, and just guessed that GetDefaultFolder(olFolderInbox) would find it for me but I don't think it did.
Private Sub Application_Startup()
Set ItemsAutoDisplayMain = Application.Session.GetDefaultFolder(olFolderInbox).Items
' Find the SpectraWAVE account.
' Search the non-default accounts for my work account.
For I = 1 To Application.Session.Accounts.Count
If Application.Session.Accounts.Item(I).DisplayName = "rhaggard@workemail.com" Then
Set ItemsAutoDisplaySW = Application.Session.Accounts.Item(I).Session.GetDefaultFolder(olFolderInbox).Items
set I = Application.Session.Accounts.Count + 1
End If
Next I
End Sub
And, of course, we need the actual event handlers themselves.
Private Sub ItemsAutoDisplay_ItemAdd(ByVal Item As Object)
On Error Resume Next
Item.Display
End Sub
Private Sub ItemsAutoDisplaySW_ItemAdd(ByVal Item As Object)
On Error Resume Next
Item.Display
End Sub
Note: Since both of these event handlers do exactly the same thing I wonder it I could dispense with ItemsAutoDisplaySW and use ItemsAutoDisplay for all autodisplay accounts?
Anyway, anyone spot what I've done wrong to break the auto display for my non-default work account?
====
Rick