Hi, I am new on the form and not very familiar with Macro's.
I found the following macro on the web.
Sub SendEmailfromOutlook()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim Path As String
Path = Application.ActiveWorkbook.Path
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Range("C3:C10")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = cell.Value
.Subject = Cells(cell.Row, "D").Value
.Body = "Dear " & Cells(cell.Row, "B").Value & "," _
& vbNewLine & vbNewLine & _
"Please find attached a list of overdue invoices. Thank you!"
.Attachments.Add (Path & "" & Cells(cell.Row, "D").Value)
.Attachments.Add (Path & "" & Cells(cell.Row, "E").Value)
.Attachments.Add (Path & "" & Cells(cell.Row, "F").Value)
'.Send
.Save
End With
Next cell
End Sub
With this macro I want to send overdue invoices to customers, some customers have more then one overdue invoice which I want to attach in the same email. My question is how I can make sure I got no error with this code when a customer has only one invoice, which means cell E and F is blank.
So if client A has 3 overdue invoice the macro workd fine, but if the macro continue to client B which has only one overdue invoice it stop working and it won't work on client C D E ...
Hope it's clear.
I found the following macro on the web.
Sub SendEmailfromOutlook()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim Path As String
Path = Application.ActiveWorkbook.Path
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Range("C3:C10")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = cell.Value
.Subject = Cells(cell.Row, "D").Value
.Body = "Dear " & Cells(cell.Row, "B").Value & "," _
& vbNewLine & vbNewLine & _
"Please find attached a list of overdue invoices. Thank you!"
.Attachments.Add (Path & "" & Cells(cell.Row, "D").Value)
.Attachments.Add (Path & "" & Cells(cell.Row, "E").Value)
.Attachments.Add (Path & "" & Cells(cell.Row, "F").Value)
'.Send
.Save
End With
Next cell
End Sub
With this macro I want to send overdue invoices to customers, some customers have more then one overdue invoice which I want to attach in the same email. My question is how I can make sure I got no error with this code when a customer has only one invoice, which means cell E and F is blank.
So if client A has 3 overdue invoice the macro workd fine, but if the macro continue to client B which has only one overdue invoice it stop working and it won't work on client C D E ...
Hope it's clear.