2010-01-05 4 views
1

Microsoft Outlook VBA에서 열려있는 모든 전자 메일 항목의 열기 이벤트를 catch 할 수 있습니까? 열어 본 메일 항목에 범주 레이블을 추가하고 싶습니다. 다른 '읽지 않음'옵션을 사용하여 다른 것에 대해 스크립트를 작성할 수 있습니다. 나는 이것을 시도했다 :의 라인에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 이벤트에 대해 알지 못했습니다. 그것은 더 잘 어울립니다. Insightor.CurrentItem.Parent.FolderPath = "\\ Mailbox - support \ Inbox"인 경우 을 추가 한 다음 을 열어 두 번째 사서함으로 제한합니다. –