我的Outlook VBA代码找不到特定的文件夹

时间:2015-05-22 14:25:23

标签: vba outlook directory outlook-vba

我有一个子读取/获取speicifc文件夹中的电子邮件项目。当我执行它似乎没有找到特定的文件夹,我不知道为什么。

子目录如下:

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

每次启动sub时,它都会返回内置消息No such folder

我的地图结构如下:

enter image description here

任何线索如何获取该文件夹并列出它的项目?

1 个答案:

答案 0 :(得分:0)

通过以下链接计算出来: Get MAPI Folder in Outlook from Folder Path

通过右键单击文件夹,我可以看到实际位置在William上,而不是直接在文件夹上。所以正确的代码是:

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