0

I'm trying to get the inbox of a specific email address where there is more than one address connected to the same Outlook.
I can only succeed if I check the main mailbox (the first listed in Outlook).

dim outlApp as Object   
dim outlNsp as Object
dim outlMapp as Object
dim outlsubMapp as Object
dim Mappar as Object

outlApp = CreateObject("Outlook.Application")
outlNsp = outlApp.GetNamespace("MAPI")

outlMapp = outlNsp.Folders.item(Mail_username)

Mappar = outlMapp.Folders
outlsubMapp = Mappar.item(6) 
'6 is olFolderInbox enum value

outlsubMapp = outlNsp.GetDefaultFolder(6)
'6 is olFolderInbox enum value

Inbox = outlsubMapp.Name

If I change Mail_username I still get the first email inbox folder.

Community
  • 1
  • 1
  • Does this answer your question? [Get reference to additional Inbox](https://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton May 08 '20 at 13:54

2 Answers2

0

This macro lists every store to which you have access and the top level folders which will include their Inboxes. It shows how to access stores and folders that are not defaults.

I am not sure if this is a complete answer but it will get you started. Try the macro then come back with any questions.

Sub ListStoresAndTopLevelFolders()

  Dim FldrCrnt As Folder
  Dim InxFldrChild As Long
  Dim InxStoreCrnt As Long
  Dim StoreCrnt As Folder

  With Application.Session
    For InxStoreCrnt = 1 To .Folders.Count
      Set StoreCrnt = .Folders(InxStoreCrnt)
      With StoreCrnt
        Debug.Print .Name
        For InxFldrChild = .Folders.Count To 1 Step -1
          Set FldrCrnt = .Folders(InxFldrChild)
          With FldrCrnt
            Debug.Print "   " & .Name
          End With
        Next
      End With
    Next
  End With

End Sub
Tony Dallimore
  • 12,335
  • 7
  • 32
  • 61
0

You can use 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. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

To get all stores in the profile you need to use the Stores property of the Namespace class:

Sub EnumerateFoldersInStores()  
 Dim colStores As Outlook.Stores  
 Dim oStore As Outlook.Store  
 Dim oRoot As Outlook.Folder 


 On Error Resume Next  
 Set colStores = Application.Session.Stores  
 For Each oStore In colStores  
   Set oRoot = oStore.GetRootFolder  
   Debug.Print (oRoot.FolderPath)  
   EnumerateFolders oRoot  
 Next  
End Sub 

Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder)  
 Dim folders As Outlook.folders  
 Dim Folder As Outlook.Folder  
 Dim foldercount As Integer 

 On Error Resume Next  
 Set folders = oFolder.folders  
 foldercount = folders.Count  
 'Check if there are any folders below oFolder  
 If foldercount Then   
   For Each Folder In folders  
     Debug.Print (Folder.FolderPath)  
     EnumerateFolders Folder  
   Next  
 End If  
End Sub
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45