How to Send an Email with VBA in Outlook 2007, 2013, and 2016

VBA Email Outlook

How to Send an Email with VBA in Outlook 2007, 2013, and 2016

The below Youtube video will show you how to send VBA emails in Outlook 2007, 2010, and 2013.


Mobile: If you don't like the video quality of the embedded video, watch it on My Youtube.


VBA Email with Attachments

– Do you send files on a daily basis to other teams at your job?
– Do you have to send an email only when certain conditions are met?

Customize the email's subject by adjusting the .Subject, the email's message by adjusting the .body, the recipients by adjusting the .to and .cc, and the attachments by adjusting the .attachments. (Source code can be found below.)


Single Attachment VBA Email Source Code:
Sub email()

Dim outapp As Object
Dim outmail As Object

Set outapp = CreateObject("Outlook.application")
Set outmail = outapp.createitem(0)

On Error Resume Next

With outmail
.to = "WhoTheEmailGetsSentTo@outlook.com;seconperson@outlook.com"
.cc = ""
.bcc = ""
.Subject = "THE SUBJECT OF THE EMAIL"
.body = "Here is the message that appears in the body of the email."
.attachments.Add ("C:\Users\ME\Desktop\Attachment.png")
.send
End With
On Error GoTo 0
Set outmail = Nothing
Set outapp = Nothing

End Sub


How to Send an Email with Multiple Attachments in VBA
If you want to send an email with multiple attachments, then it's the same code as the above. Just add another line as described below.


Multiple Attachments Email in VBA Source Code:

Sub email2()

Dim outapp As Object
Dim outmail As Object

Set outapp = CreateObject("Outlook.application")
Set outmail = outapp.createitem(0)

On Error Resume Next

With outmail
.to = "WhoTheEmailGetsSentTo@outlook.com"
.cc = ""
.bcc = ""
.Subject = "THE SUBJECT OF THE EMAIL"
.body = "Here is the message that appears in the body of the email."
.ATTACHMENTS.Add ("C:\Users\Nonaluuluu\Desktop\Attachment1.png"
.ATTACHMENTS.Add ("C:\Users\Nonaluuluu\Desktop\Attachment2.png")
.send
End With
On Error GoTo 0
Set outmail = Nothing
Set outapp = Nothing

End Sub


Filepaths:
If you're unsure of how to get the file's filepath, then right click the file, go to Properties and copy the words next to location as pictured below. Alternatively, you can click inside of the top arrow picured below to get the majority of the file path. Just add in the file's name and file type afterwards to get the full filepath. File types are three letters after a . such as .csv, .mp3, .xls, .xlsx, and .xlsm.

Comments are closed.