Nicolas
Nicolas

Reputation: 2376

How to find a specific folder?

I have a sub to read/get the email items in a specific folder.

It doesn't find the folder.

Sub HowManyEmails()

    Dim objOutlook As Object, objnSpace As Object, objFolder As MAPIFolder
    Dim EmailCount As Integer
    Set objOutlook = CreateObject("Outlook.Application")
    Set objnSpace = objOutlook.GetNamespace("MAPI")

    On Error Resume Next
    Set objFolder = objnSpace.folders("#MemoScan")
    If Err.Number <> 0 Then
        Err.Clear
        MsgBox "No such folder."
        Exit Sub
    End If

    EmailCount = objFolder.Items.Count

    MsgBox "Number of emails in the folder: " & EmailCount, , "email count"

    Set objFolder = Nothing
    Set objnSpace = Nothing
    Set objOutlook = Nothing
End Sub

It returns the built-in message "No such folder.".

My folder structure:
enter image description here

How can I get that folder?

Upvotes: 0

Views: 5985

Answers (1)

Nicolas
Nicolas

Reputation: 2376

Figured it out thanks to the following link: Get MAPI Folder in Outlook from Folder Path.

By right clicking on the folder I could see the actual location was on William and not directly on the folder. So the right code is:

Set objFolder = objnSpace.folders("William").folders("#MemoScan")

Upvotes: 1

Related Questions