Hello. I have a VBA that is pulling files out of excel and creating emails. I have an extensive master list with potential files, which may or may not be found on a given week. My issue is, when it runs, if it cannot find one of the files, then the module stops.
Is there a way that if a file is not found, it can move onto the next one and so on and so forth without stopping? Here is my code:
Is there a way that if a file is not found, it can move onto the next one and so on and so forth without stopping? Here is my code:
Code:
Sub SendMultipleEmails()
Dim Mail_Object, OutApp As Variant
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For i = 2 To lastrow
Set Mail_Object = CreateObject("Outlook.Application")
Set OutApp = Mail_Object.CreateItem(0)
With OutApp
.Subject = "Open Order Report - " & Cells(i, 4).Value & " - " & Date
Dim sMsgBody As String
.Body = "Hello " & Cells(i, 1).Value & "," & vbCr & vbCr
.Body = .Body & "Could you please provide a delivery schedule/status for the attached:" & vbCr & vbCr
.Body = .Body & "'OK if the date is acceptable in the 'STATUS/Long Text' field, or specify date in which you will ship - in the 'Committed Supplier Reschedule Date" & vbCr & vbCr
.Body = .Body & "Any additional comments can be added to the 'STATUS/Long Text' field. " & vbCr & vbCr
.Body = .Body & "Thank you, and have a great day!" & vbCr & vbCr
.Body = .Body
.To = Cells(i, 2).Value
.Attachments.Add Cells(i, 3).Value
.Send
End With
Next i
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub