确认所选邮件项目位于特定文件夹中

时间:2018-06-09 00:47:22

标签: vba outlook outlook-vba

我正在尝试构建一个小支票,确认我当前选择的邮件项目在某个文件夹中(在这种情况下是收件箱),然后继续使用我的其余代码来保存电子邮件。

有些事情:

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语法来使其工作。

2 个答案:

答案 0 :(得分:0)

看起来我可能已经回答了我自己的问题,但我会留在这里以防万一有人碰巧跟随我的脚步。

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

答案 1 :(得分:0)

不要比较指针 - 它不起作用。使用Namespace.CompareEntryIDs

比较条目ID
If Not ns.CompareEntryIDs(ActiveExplorer.CurrentFolder.EntryID, objFolder.EntryID) Then
  ...
相关问题