MarcinSzaleniec
MarcinSzaleniec

Reputation: 2256

Reference to non-default non-English inbox

I am trying set a reference to a non-default inbox in MS Outlook. I have found a code in SO,

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")

which is OK when inbox is named "Inbox".

There is a possibility for inboxes to be named in non-English languages.

You may refer to the default inbox by

objNS.getdefaultfolder(6)

But what about non-defaults?

Upvotes: 1

Views: 108

Answers (1)

niton
niton

Reputation: 9179

You should be able to get inboxes by Store index or name.

Option Explicit

Sub Inbox_by_Store()

Dim allStores As Stores
Dim storeInbox As Folder

Dim i As Long

Set allStores = Session.Stores

For i = 1 To allStores.count

    Debug.Print i & " DisplayName - " & allStores(i).DisplayName

    Set storeInbox = Nothing
    On Error Resume Next
    Set storeInbox = allStores(i).GetDefaultFolder(olFolderInbox)
    On Error GoTo 0

    If Not storeInbox Is Nothing Then
        storeInbox.Display
    End If

Next

ExitRoutine:
    Set allStores = Nothing
    Set storeInbox = Nothing

End Sub

Upvotes: 1

Related Questions