2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VBAからOutlookを使ってメールを送信するサンプル(添付に対応)

Posted at
test.xlsm
Sub test()

    '宣言
    Dim outlook        As Object
    Dim mail_to        As String
    Dim mail_cc        As String
    Dim mail_subject   As String
    Dim mail_body      As String
    Dim mail_file_path As String
    
    '代入
    Set outlook    = CreateObject("Outlook.Application")
    mail_to        = "sozaiya@dummy.com"
    mail_cc        = "info@dummy.com"
    mail_subject   = "test"
    mail_body      = "テストです。"
    
    '空白だったら添付ファイルなしと判定
    mail_file_path = "C:\Users\xxxx\Desktop\test.txt"

    With outlook.CreateItem(0)
        .to      = mail_to
        .cc      = mail_cc
        .Subject = mail_subject
        .body    = mail_body
        If mail_file_path <> "" Then .Attachments.Add mail_file_path
        
        '送信確認画面を表示
        .display

        'いきなり送信
        .send
    End With
End Sub
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?