2010-01-05 15 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

相關問題