Hi All,
This is my first post and was hoping some guidance reg. my issue.
So i have the following code which creates an email and attaches files to it. However it's not necessary that each file is going to exist every time, so the pathname could be wrong. I am very new to the world of macros and would appreciate your help.
1. So incase my macro doesn't find the path ("can not find path" error.), it should still go ahead and check other files and attach the files if they exist. Basically surpass the error of not finding path
2. and display the email, where I can decide if I should send the email or not.
many many thanks in advance
--------------------------
Sub send_email_with_multiple_attachements()
Dim o As Outlook.Application
Set o = New Outlook.Application
Dim omail As Outlook.MailItem
Dim File As String
Dim i As Long
For i = 2 To Range("a100").End(xlUp).Row
Set omail = o.CreateItem(olMailItem)
With omail
.Body = "Dear " & Cells(i, 1).Value & "," & Cells(i, 4).Value
.To = Cells(i, 2).Value
.CC = Cells(i, 5).Value
.Subject = Cells(i, 3).Value
.Attachments.Add Cells(i, 6).Value
.Attachments.Add Cells(i, 7).Value
.Attachments.Add Cells(i, 8).Value
.Attachments.Add Cells(i, 9).Value
.Display
End With
Next
End Sub
This is my first post and was hoping some guidance reg. my issue.
So i have the following code which creates an email and attaches files to it. However it's not necessary that each file is going to exist every time, so the pathname could be wrong. I am very new to the world of macros and would appreciate your help.
1. So incase my macro doesn't find the path ("can not find path" error.), it should still go ahead and check other files and attach the files if they exist. Basically surpass the error of not finding path
2. and display the email, where I can decide if I should send the email or not.
many many thanks in advance
--------------------------
Sub send_email_with_multiple_attachements()
Dim o As Outlook.Application
Set o = New Outlook.Application
Dim omail As Outlook.MailItem
Dim File As String
Dim i As Long
For i = 2 To Range("a100").End(xlUp).Row
Set omail = o.CreateItem(olMailItem)
With omail
.Body = "Dear " & Cells(i, 1).Value & "," & Cells(i, 4).Value
.To = Cells(i, 2).Value
.CC = Cells(i, 5).Value
.Subject = Cells(i, 3).Value
.Attachments.Add Cells(i, 6).Value
.Attachments.Add Cells(i, 7).Value
.Attachments.Add Cells(i, 8).Value
.Attachments.Add Cells(i, 9).Value
.Display
End With
Next
End Sub