Sub Mail_Create()
'Excelファイルを添付したメールをメールに添付する
Dim ol As Outlook.Application
Dim MI As Outlook.MailItem
Dim str_Path As String
Dim Attach_Path As String
Set ol = CreateObject("Outlook.Application")
Set MI = ol.CreateItem(olMailItem)
str_Path = "C:\Users\User\Desktop\VBA関連\VBA練習\保存用\test.msg"
Attach_Path = "C:\Users\User\Desktop\VBA関連\VBA練習\保存用\test.xlsx"
'メール各設定
With MI
.SentOnBehalfOfName = "差出人" '差出人
.To = "To宛先" 'TO
.CC = "CC" 'CC
.BCC = "BCC" 'BCC
.Subject = "件名" '件名
'本文
.Body = "本文テスト"
'メールにテスト用のExcelファイルを添付
.Attachments.Add Attach_Path
'Excelファイルを添付したメールを保存
.SaveAs str_Path, olMSG
End With
Set MI = Nothing
'------------------------------
Set MI = ol.CreateItem(olMailItem)
'メール各設定
With MI
.SentOnBehalfOfName = "差出人" '差出人
.To = "To宛先" 'TO
.CC = "CC" 'CC
.BCC = "BCC" 'BCC
.Subject = "件名" '件名
'本文
.Body = "本文テスト"
'保存したメールファイルを添付
.Attachments.Add str_Path
'メール表示
.Display
End With
Set ol = Nothing
Set MI = Nothing
End Sub
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme