Hello folks.
I have a code to attached a .pdf and email to recipients on an excel sheet. The current code only attaches one file, however I would like to attach a second file to the email called "CEO Letter.pdf", found in the same directory, along with the particular file. Here is my spreadsheet:
Here is my code:
I have a code to attached a .pdf and email to recipients on an excel sheet. The current code only attaches one file, however I would like to attach a second file to the email called "CEO Letter.pdf", found in the same directory, along with the particular file. Here is my spreadsheet:
Here is my code:
VBA Code:
Option Explicit
Sub SendEmailAttachment()
Dim Email As String
Dim subj As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As Integer
Dim attachment As String
Dim x As Integer
x = 2
Do While Sheet1.Cells(x, 1) <> ""
Set outlookapp = CreateObject("Outlook.Application")
Set outlookmailitem = outlookapp.createitem(0)
Set myAttachments = outlookmailitem.Attachments
path = "C:\Users\JAMazorra\OneDrive - Lane Construction\Desktop\Statements"
edress = Sheet1.Cells(x, 1)
subj = Sheet1.Cells(x, 2)
filename = Sheet1.Cells(x, 3)
attachment = path + filename
outlookmailitem.To = Email
outlookmailitem.cc = ""
outlookmailitem.bcc = ""
outlookmailitem.Subject = subj
outlookmailitem.body = "Please find your statement attached" & vbCrLf & "Best Regards"
myAttachments.Add (attachment)
outlookmailitem.display
outlookmailitem.send
lastrow = lastrow + 1
edress = ""
x = x + 1
Loop
Set outlookapp = Nothing
Set outlookmailitem = Nothing
End Sub