Excel方眼紙からの脱却

VBAのことと、その他いろいろメモ。

Outlookで受信したメールを処理する

Outlookでメールを受信すると、Application.NewMailEx イベントが発生します。
このとき取得できるEntryIDCollectionで、GetItemFromIDを呼び出すと、
受信したメールを、あれこれできるようになります。

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)

    Dim myMsg As Object
    Set myMsg = Session.GetItemFromID(EntryIDCollection)
    
    If myMsg.Sender.Address = "xxx@xx.xx" Then
        MsgBox myMsg.Sender.Name & "からのメッセージです。"
    End If
    
End Sub