I have a sheet where in column A I have email addresses and in column B the client IDs. I would like to use the client IDs to match the file name,
so the right file can be grabbed from a folder and then be attached to an email, using the email address in column A. here is a sample data:
Column A | Column B
client1@yahoo.com | 12345
client2@gmail.com | 67890
The files in the c:\PDF Files\Invoice folder: Invoice12345.pdf Invoice67890.pdf
I am trying to use the following macro to attach Invoice12345.pdf to an email using outlook and send it to client1@yahoo.com and repeat it until
there are no more emails in column A. for some reason, sometimes it works but only creates one email and crashes when it tries to get to the second record.
here is the error message: "Run-time error'-2147024894 (80070002)': Cannot find this file. Verify the path and file name are correct."
Thank you in advance for your help.
Sub Email()
Dim BlankFound As Boolean Dim x As Long
Do While BlankFound = False
x = x + 1
If Cells(x, "A").Value = "" Then
BlankFound = True
End If
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "Booking Invoice"
nameList = Sheets("Sheet1").Cells(x, "A").Value
Email_Send_To = nameList
Email_Cc = ""
Email_Bcc = ""
Email_Body = "Here's your Invoice"
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(o)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.CC = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.Attachments.Add ("c:\PDF Files\Invoice\Invoice" & Cells(x, "B") & ".pdf")
.Display
' .send
End With ' MsgBox "E-mail successfully sent" ' Application.DisplayAlerts = False
Loop
End Sub
so the right file can be grabbed from a folder and then be attached to an email, using the email address in column A. here is a sample data:
Column A | Column B
client1@yahoo.com | 12345
client2@gmail.com | 67890
The files in the c:\PDF Files\Invoice folder: Invoice12345.pdf Invoice67890.pdf
I am trying to use the following macro to attach Invoice12345.pdf to an email using outlook and send it to client1@yahoo.com and repeat it until
there are no more emails in column A. for some reason, sometimes it works but only creates one email and crashes when it tries to get to the second record.
here is the error message: "Run-time error'-2147024894 (80070002)': Cannot find this file. Verify the path and file name are correct."
Thank you in advance for your help.
Sub Email()
Dim BlankFound As Boolean Dim x As Long
Do While BlankFound = False
x = x + 1
If Cells(x, "A").Value = "" Then
BlankFound = True
End If
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "Booking Invoice"
nameList = Sheets("Sheet1").Cells(x, "A").Value
Email_Send_To = nameList
Email_Cc = ""
Email_Bcc = ""
Email_Body = "Here's your Invoice"
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(o)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.CC = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.Attachments.Add ("c:\PDF Files\Invoice\Invoice" & Cells(x, "B") & ".pdf")
.Display
' .send
End With ' MsgBox "E-mail successfully sent" ' Application.DisplayAlerts = False
Loop
End Sub