24

I'm using Outlook 2007 - and have my main mailbox: Tait, Mark

I have also added another mailbox to my profile: Procurement, Request

Both appear as top level folders within Outlook:

Mailbox - Tait, Mark> -Conversation History
-Deleted Items
-Drafts
-Inbox
-Junk E-Mail

Mailbox - Procurement, Request
--Conversation History
--Deleted Items
--Drafts
--Inbox
--Junk E-Mail

I can get a reference to my default Inbox (Tait, Mark) using:
Set Inbox = ns.GetDefaultFolder(olFolderInbox)

How do I get a reference to the Inbox in the "Procurement, Request" mailbox?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Mark
  • 7,778
  • 24
  • 89
  • 147

3 Answers3

26

Something like this should do the trick

Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = GetNamespace("MAPI")
Set objFolder = objNS.Folders("Procurement, Request")
Set objFolder = objFolder.Folders("Inbox")

This link has some useful code for handling different Inboxes - it may be of interest

brettdj
  • 54,857
  • 16
  • 114
  • 177
  • @MarkTait glad to have helped :) – brettdj Jan 31 '12 at 09:59
  • This will work only if the store was already added to the curent profile. – Dmitry Streblechenko Oct 12 '17 at 16:09
  • @brettdj please how can I automate the Set objFolder = objNS.Folders("Procurement, Request") and Set objFolder = objFolder.Folders("Inbox") into a function like Public Sub AppResponseManage(Item As Outlook.MailItem) that receive a Mailitem as a parameter (in other words how can I extract the mailbox name and the inbox folder name from a mail item?) Thanks a lot – Giamma Theo Jun 05 '18 at 09:18
7
Dim olNS As NameSpace
Dim InputFolder As Outlook.MAPIFolder
Set olNS = Outlook.Application.GetNamespace("MAPI")

' Get reference to folder in users Mailbox for Input
Set InputFolder = olNS.Folders("Procurement, Request").Folders("Inbox")

' all the emails in the shared inbox are represented by:
InputFolder.Items
itoctopus
  • 4,133
  • 4
  • 32
  • 44
Bruno
  • 71
  • 1
  • 1
6

Use Namespace.GetSharedDefaultFolder. It will work even if the mailbox is not opened in the current profile. You still need to have the right to open the mailbox and access the folder in question of course:

Set vNamespace = Application.GetNamespace("MAPI")
set vRecipient = vNamespace.CreateRecipient("Procurement, Request")
if vRecipient.Resolve Then
  set vFolder = vNamespace.GetSharedDefaultFolder(vRecipient, olFolderInbox)
End If

If you need to open the other user's mailbox (with all off its folders), you can use Redemption (I am its author) and its RDOSession.GetSharedMailbox method:

 set Session = CreateObject("Redemption.RDOSession")
 Session.MAPIOBJECT = Application.Session.MAPIOBJECT
 set Store = Session.GetSharedMailbox("Procurement, Request")
 set vFolder = Store.GetDefaultFolder(olFolderInbox)
 MsgBox "The address of the mailbox owner: " & Store.Owner.Address
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78