-2

Hi I am using the following macro to create a batch of new folders in an inbox. It performs fantastically however I can't for the life of me figure out how to select a different inbox (inbox1, inbox2, inbox3) all different email accounts.

code is here: http://www.slipstick.com/macros/Create%20subfolders%20at%20multiple%20levels.txt

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • Please don't post links to the code. Instead include the code within your question. Links may disappear after a while and the question gets useless to future readers. According [ask] and [help] everthing that is needed to understand the question (including code) needs to be within the question itself. Please [edit] your question and include the code. – Pᴇʜ Mar 22 '21 at 07:09
  • 1
    Possible duplicate of [Get reference to additional Inbox](https://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton Mar 22 '21 at 13:13

2 Answers2

0

Instead of using Session.GetDefaultFolder, call Session.CreateRecipient / Recipient.Resolve / Session.GetSharedDefaultFolder

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

If all these inboxes are configured in Outlook you can use the Stores collection to iterate over stores and using the Store.GetDefaultFolder method which returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument.

If you need to access shared mailboxes you need to use the NameSpace.GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user.

Sub ResolveName() 
 Dim myNamespace As Outlook.NameSpace 
 Dim myRecipient As Outlook.Recipient 
 Dim CalendarFolder As Outlook.Folder 
 
 Set myNamespace = Application.GetNamespace("MAPI")
 Set myRecipient = myNamespace.CreateRecipient("Dan Wilson") 
 myRecipient.Resolve 
 If myRecipient.Resolved Then 
   Call ShowCalendar(myNamespace, myRecipient) 
 End If
End Sub
 
Sub ShowCalendar(myNamespace, myRecipient) 
 Dim CalendarFolder As Outlook.Folder 
 
 Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar) 
 CalendarFolder.Display 
End Sub
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45