2011-07-27 2 views
3

Outlook에서 클릭 한 Outlook 메일에서 .To 줄에 액세스하려고합니다.항목 Outlook에서 추출 olMail-Item on ItemLoad VBA- 이벤트

특히 메일이 특정 이메일로 전송되었는지 확인하고 싶습니다.

넓은보기 :
내가 메일을 클릭하고 내 서브 루틴이이 특정 이메일 주소 (Item.To 필드)로 전송되었음을 알았습니다. 이 경우 사용자가 해당 메일에 회신하기로 선택하면 (reply-event) 회신 메일의 참조 필드에 메일이 전송 될 다른 이메일 주소가 자동으로 포함됩니다. 내가 지금까지 가지고와 작동하지 않는 무엇

:

Private Sub Application_ItemLoad(ByVal Item As Object) 
    MsgBox "To: " & Item.To 
End Sub 

오류 : 가치와 요소의 방법이 이벤트에서 처리 할 수 ​​없습니다.

.To 필드에 액세스하려면 mailitem-object으로 선언하려면 어떻게 든 객체를 캐스팅해야합니까? 또는 다른 유용한 제안이 있습니까?

+0

내 코드를 사용해 보셨습니까? 그것이 효과가 있는지 알려 주시면 감사하겠습니다. – JimmyPena

답변

0

Application_ItemLoad는 Outlook 2007에 도입되었으므로 귀하의 버전이라고 가정합니다.

나는 이것을 테스트 할 수 모르지만, 그것을 작동합니다 :

Sub CheckRecips() 

Dim msg As Outlook.mailItem 
Dim msgRecips As Outlook.Recipients 
Dim msgRecip As Outlook.Recipient 
Dim msgReply As Outlook.mailItem 
Dim found As Boolean 
Dim replyRecip As Outlook.Recipient 

If TypeName(Outlook.ActiveExplorer.Selection(1)) = "MailItem" Then 
    Set msg = Outlook.ActiveExplorer.Selection(1) 
    Set msgRecips = msg.Recipients 

    For Each msgRecip In msgRecips 
    If msgRecip.Type = olTo And msgRecip.Address = "email address you're looking for" Then 
     ' we found it, exit loop 
     found = True 
     Exit For 
    End If 
    Next msgRecip 

    ' create reply 
    Set msgReply = msg.Reply 

    ' if email address was on recipient list, CC someone else on reply 
    If found Then 
     Set replyRecip = msgReply.Recipients.Add("someone else who should be CC'd") 
     replyRecip.Type = olCC 
    End If 

    msgReply.Display 
End If 

End Sub 

은 교체를받은 수있는 "특정"사람의 이메일 주소로 "당신이 찾고있는 이메일 주소" 이메일.

"다른 사람이 CC'd이어야합니다"를 해당 특정 사람이 메시지를받을 때 참조 할 사람의 전자 메일 주소로 바꿉니다.

Assign this to a toolbar button 그리고 필요할 때마다 사용하십시오.

1

응용 프로그램 ItemLoad 이벤트는 항목이 완전히 초기화되지 않은 경우 발생합니다.

Public WithEvents myItem As Outlook.mailItem 

Private Sub Application_ItemLoad(ByVal Item As Object) 
    If (TypeOf Item Is mailItem) Then 
     Set myItem = Item 
    End If 
End Sub 

Private Sub myItem_Read() 
... 
End Sub 
: 우리가 "ThisOutlookSession"클래스에 아래의 코드로 원하는 이벤트를 달성 고원 등 열기, 읽기 (당신이 원하는 아마도 하나)와 같은 다른 항목 이벤트를, 훅하는 데 유용합니다

건배!