【VBA】Send email by Outlook

You can send email by Outlook
from VBA!

PR

VBA Code

Sub sendEMailSample()

    Dim objApp As Object
    Dim objMail As Object
    
    Set objApp = CreateObject("Outlook.Application")
    Set objMail = objApp.CreateItem(0)
    
    With objMail
        'To
        .to = "XXXXX@gmail.com"
        'Cc
        .cc = "XXXXX@gmail.com"
        'Bcc
        .bcc = "XXXXX@gmail.com"
        'title
        .Subject = "Test Email"
        'format(1:text、2:HTML)
        .BodyFormat = 1
        'Body
        .Body = "Send mail form VBA."
        'attachment file
        .Attachments.Add "C:\Users\XXXX\Desktop\aiueo.txt"
        'Send mail
        .Send
    End With
    
    Set objMail = Nothing
    Set objApp = Nothing
    
End Sub
PR

Result

You was able to send email by Outlook from VBA.

Result
Result
PR

FYI

For more information about following, see the following official online manual:

MailItem Object

タイトルとURLをコピーしました