无法根据主题search邮件

我正在尝试在Excel工作表中根据列中提到的列表search邮件。 下面是我写的VBA代码。 但它不工作。 请帮忙:

Sub Test() Dim olApp As Outlook.Application Dim olNs As Namespace Dim Fldr As MAPIFolder Dim olMail As Variant Dim i As Integer Dim rng As Range Dim n As Variant Set olApp = New Outlook.Application Set olNs = olApp.GetNamespace("MAPI") Set Fldr = olNs.GetDefaultFolder("Test1" as OlDefaultFolders) 'Set rng = [D3:D10] n = Cells(4, 4).Value 'For Each n In rng 'i = Int(n) 'Cells(i, 10).Text = Cells(i, 4).Text For Each olMail In Fldr.Items If InStr(olMail.Subject, "n") <> 0 Then Cells(3, 4).Offset(0, 1).Value = "Y" Else Cells(3, 4).Offset(0, 1).Value = "N" End If Next olMail 'Next n End Sub 

你不能使用GetDefaultFolder,除了 – 默认文件夹(收件箱,联系人,日历等)。 要获取特定的文件夹,您需要知道文件夹的EntryID并使用NameSpace.GetFolderFromID或从特定的根文件夹对象(例如myInboxFolderObject.Folders(“MyInboxSubFolder”))的“文件夹”集合中“漫游”。

另请参阅“ 枚举,search和筛选文件夹中的项目 ”。