pharrm
pharrm

Reputation: 101

Use Excel VBA to search specific outlook inbox in multi-inbox environment

I have tried search a bunch of forums but have not been able to find a solution to my problem. I will admit that my understanding of VBA objects is limited. I have an Excel VBA report that creates an Outlook object and then scans the Outlook default inbox until it finds an unread email. I have gotten the code to work perfectly on my computer. However, the computer that will run this has two (2) different email addresses/inboxes tied to Outlook (One is a personal inbox, and the other is group inbox).

The code I have been using to search my personal inbox is this (it continues on to search for unread emails, etc...):

    Application.ScreenUpdating = False
    Dim oOlAp As Object, oOlns As Object, oOlInb As Object
    Dim oOlItm As Object, oOlAtch As Object
    '~~> New File Name for the attachment
    Dim NewFileName As String
    NewFileName = "ActInv Export"
    '~~> Get Outlook instance
    Set oOlAp = GetObject(, "Outlook.application")
    Set oOlns = oOlAp.GetNamespace("MAPI")
    Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox)

However, this only points to the default inbox (ie the personal email). How do I change it to set the object to search the group email inbox?

Upvotes: 1

Views: 4991

Answers (1)

Instant Breakfast
Instant Breakfast

Reputation: 1445

I can't be sure (since I'm not on a computer running Outlook right now and thus can't play around with it), but I think the answer to your question might be contained in the answer to this question on building a tracker for a shared Outlook mailbox.

I'm thinking the key lies in the line

Set f = olns.Folders("Mailbox - Name, Name")

which is parallel to but different from your statement

Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox)

Good luck!

Upvotes: 1

Related Questions