0

Outlook VBA to execute script on shared mailbox, not main mailbox I am trying to get this VBA script to execute not on my inbox, but on the shared mailbox which is attached to my profile but not directly under my main inbox. It is listed as a separate email box.

Sub sortbysubject() 
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objInbox = objNamespace.GetDefaultFolder(olFolderInbox)
strFolderName = objInbox.Parent
Set objMailbox = objNamespace.Folders("Credit_SP Trading Floor Support")
Set objFolder = objMailbox.Folders("Inbox")
Set colItems = objFolder.Items
For Each objItem In colItems
    Wscript.Echo objItem.Subject
Next
End Sub
capser
  • 2,442
  • 5
  • 42
  • 74

1 Answers1

0

Instead of calling objNamespace.GetDefaultFolder, call objNamespace.CreateRecipient, then pass the returned Recipient object to objNamespace.GetSharedDefaultFolder.

If this is not a delegate mailbox, but rather another Exchange account already added to your profile, you can find the mailbox in the objNamespace.Stores collection, then call Store.GetDefaultFolder.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78