Vba 确认所选邮件项目位于特定文件夹中
我正在尝试建立一个小检查,以确认我当前选择的邮件项目位于某个文件夹(在本例中为收件箱)中,然后再使用我的其余代码保存电子邮件 大致如下:Vba 确认所选邮件项目位于特定文件夹中,vba,outlook,Vba,Outlook,我正在尝试建立一个小检查,以确认我当前选择的邮件项目位于某个文件夹(在本例中为收件箱)中,然后再使用我的其余代码保存电子邮件 大致如下: If Not Application.ActiveExplorer.Selection = .Folder(olFolderInbox) MsgBox Currently selected email is not in the inbox! Item skipped.", 1, "Mail Item Selection Error" Else End If
If Not Application.ActiveExplorer.Selection = .Folder(olFolderInbox)
MsgBox Currently selected email is not in the inbox! Item skipped.", 1, "Mail Item Selection Error"
Else
End If
或将当前代码修改为:
For Each oMail In Application.ActiveExplorer.Selection And Inside .Folder(olFolderInbox)
//Rest of code here
我假设这是一个足够简单的检查,但我似乎找不到正确的VBA语法来让它工作。看起来我可能已经回答了我自己的问题,但我将把这个留在这里,以防有一天有人碰巧追随我的脚步
Dim objFolder As Folder
Set objFolder = ns.GetDefaultFolder(olFolderInbox)
If Not ActiveExplorer.CurrentFolder = objFolder Then
MsgBox "Currently selected email is not in the inbox! Item not saved.", 1, "Mail Item Selection Error"
Exit Sub
Else
End If
不要比较指针-它将不起作用。使用Namespace.CompareEntryIDs比较条目ID
If Not ns.CompareEntryIDs(ActiveExplorer.CurrentFolder.EntryID, objFolder.EntryID) Then
...
小心使用
GetDefaultFolder
。当我第一次使用Outlook时,默认安装有一个存储区(扩展名为PST或OST的文件),所有电子邮件都加载到该存储区。现在,默认安装为每个帐户有一个存储,外加一个额外的存储。帐户存储将在文件夹窗格中列出,类似于“johndoe@gmail.com". 额外存储将列为“outlook数据文件”。每个商店都有自己的收件箱。您的电子邮件将加载到相应帐户存储中的收件箱中,但默认收件箱(如GetDefaultFolder
所报告)将位于“outlook数据文件”中。