Send email using Outlook object with attachments
With AI-generated post image.
From https://www.vbausefulcodes.com/vbausefulcodes/36/send-mail-in-outlook-with-attachments-from-excel-vba
Sub EmailSend_Outlook(ToAddr, Subject, Body, Optional AttchFile = "", Optional CCAddr = "")
' Send Mail in Outlook with Attachments from Excel VBA
' If you ever wanted to automate the task of sending emails with attachments, then this is the code for you. This code will automatically add attachments to the emails along with the body content.
' https://www.vbausefulcodes.com/vbausefulcodes/36/send-mail-in-outlook-with-attachments-from-excel-vba
' ##NOT Tested## '
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
' Dim strLocation As String
' strLocation = "C:\Users\welcome\Desktop\ap.txt" ' Specify your own file name with path
With OutMail
.To = ToAddr ' ""
.CC = CCAddr ' ""
.BCC = ""
.Subject = Subject ' "Mail with Attachments" ' Specify your Subject line
.Body = Body ' "Check More Codes in VBA Useful Codes Android App!" ' Specify your body text
If AttchFile > "" Then .Attachments.Add (AttchFile)
' .Display
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
' With Application
' .ScreenUpdating = True
' .EnableEvents = True
' End With
End Sub
' Send Mail in Outlook with Attachments from Excel VBA
' If you ever wanted to automate the task of sending emails with attachments, then this is the code for you. This code will automatically add attachments to the emails along with the body content.
' https://www.vbausefulcodes.com/vbausefulcodes/36/send-mail-in-outlook-with-attachments-from-excel-vba
' ##NOT Tested## '
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
' Dim strLocation As String
' strLocation = "C:\Users\welcome\Desktop\ap.txt" ' Specify your own file name with path
With OutMail
.To = ToAddr ' ""
.CC = CCAddr ' ""
.BCC = ""
.Subject = Subject ' "Mail with Attachments" ' Specify your Subject line
.Body = Body ' "Check More Codes in VBA Useful Codes Android App!" ' Specify your body text
If AttchFile > "" Then .Attachments.Add (AttchFile)
' .Display
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
' With Application
' .ScreenUpdating = True
' .EnableEvents = True
' End With
End Sub
oAddr, Subject, Body, Optional AttchFile = "", Optional CCAddr = ""
Views 87
Downloads 33
CodeID
DB ID