2010-01-05 66 views
1

在Microsoft Outlook VBA中是否可以捕获任何打开的邮件项目的打开事件?我想为我打开的任何邮件项目添加一个类别标签,以便为替代别的项目提供替代的“未读”选项。我已经试过这样:Outlook VBA:在未清项目上添加类别

Private Sub MailItem_Open() 
    MsgBox "test" 
End Sub 

回答

2

也许事情就行:

Public WithEvents myOlInspectors As Outlook.Inspectors 
Public myInspectorsCollection As New Collection 

Private Sub Application_Startup() 
    Initialize_handler 
End Sub 

Public Sub Initialize_handler() 
    Set myOlInspectors = Application.Inspectors 
End Sub 

Private Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector) 
If (Inspector.CurrentItem.Class = olMail) Then 

    If Inspector.CurrentItem.Parent = "Inbox" Then 
     strCats = Inspector.CurrentItem.Categories 

     If InStr(strCats, "Read") = 0 Then 
      If Not strCats = vbNullString Then 
       strCats = strCats & "," 
      End If 
      strCats = strCats & "Read" 
      Inspector.CurrentItem.Categories = strCats 
      Inspector.CurrentItem.Save 
     End If 
    End If 
End If 
End Sub 

上面应该在ThisOutlookSession。您需要确保您的安全级别允许使用宏。

+0

谢谢,我试图抓住ItemChange事件,但我不知道NewInspector事件。它确实更好。我添加了 如果Inspector.CurrentItem.Parent.FolderPath =“\\ Mailbox - support \ Inbox”然后 将其限制为第二个邮箱,我已打开。 – 2010-01-07 07:33:31

相关问题