スナックelve 本店

バツイチ40代女の日記です

送信済みメールのメールアドレスの一覧が欲しい

日報を書くのに、その日の行動を振り返りどこの誰に何を送ったのかを入力するんすが(本当は都度入力なのだがどうしても漏れる)、メールアドレスの一覧がアレばそこから顧客リストの引っ張ってcsv入力できるのになぁ・・・と。
特定フォルダのメール一覧を取得はできるようになったのだが、mailItem.toには表示名(?)が入ってしまう。

Sub test()
    'クリア
    Range("A:A").ClearContents
    Dim oap As New Outlook.Application
    Dim fols As Outlook.Folder
    Dim itms As Outlook.Items
    Dim itm As Outlook.MailItem
    '送信フォルダ(自分のメールアドレスにしてね)
    Set fols = oap.Session.Accounts("hygienic53@gmail.com").DeliveryStore.GetDefaultFolder(olFolderSentMail)
    'メールアイテム
    Set itms = fols.Items
    '新しい順
    itms.Sort "[送信日時]", True
    
    '5件出力
    Dim i As Integer: i = 1
    For Each itm In itms
        Cells(i, 1) = itm.To
        i = i + 1
        If i > 5 Then Exit For
    Next
End Sub

結果、メアド不明

とりあえず送付先1件だけわかればいいなら

Sub test()
    'クリア
    Range("A:A").ClearContents
    Dim oap As New Outlook.Application
    Dim fols As Outlook.Folder
    Dim re As Outlook.Recipient
    Dim itms As Outlook.Items
    Dim itm As Outlook.MailItem
    '送信フォルダ
    Set fols = oap.Session.Accounts("hygienic53@gmail.com").DeliveryStore.GetDefaultFolder(olFolderSentMail)
    'メールアイテム
    Set itms = fols.Items
    '新しい順
    itms.Sort "[送信日時]", True
    
    '5件出力
    Dim i As Integer: i = 1
    For Each itm In itms
        Cells(i, 1) = itm.Recipients(1).Address
        i = i + 1
        If i > 5 Then Exit For
    Next
End Sub

Recipients(0)にしてハマった(;´Д`)

共有メール受信メールの一覧

snack.elve.club