Give this code a whirl:
Sub emailattachpdffile()
Dim OutApp As Object
Dim OutMail As Object
Dim i As Integer
Dim lr As Integer
Dim Path As String
Application.ScreenUpdating = False
lr = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row
On Error Resume Next
For i = 2 To Sheet1.Cells(Rows.Count, "B").End(xlUp).Row
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'If IsEmpty(Cells(i, "AP").Value) Then 'Check for date
Path = "C:\Users\Sanjay Kumar\Desktop\F&F\" & Sheet1.Cells(i, "C") & "\"
With OutMail
.To = Sheet1.Cells(i, "AN").Value
.CC = ""
.Subject = "Full & Final Settlement || " & Sheet1.Cells(i, "B") & " - " & Sheet1.Cells(i, "C")
.HTMLBody = "Dear " & Cells(i, "D") & "," & Chr(11) & Chr(11) & "Please find the full Final Settlement." & Chr(11) & Chr(11) & "Thanks and Regards" & Chr(11) & Chr(11) & .HTMLBody
.Attachments.Add Path & Sheet1.Cells(i, "C") & "_Payslip.pdf"
If Err.Number <> 0 And Err.Number = -2147024893 Then
'MsgBox "Missing Path at row # " & i
Sheet1.Cells(i, "AQ").Value = "File has NOT been sent"
On Error GoTo -1
GoTo skip
End If
.Attachments.Add Path & Sheet1.Cells(i, "C") & "_IT.pdf"
If Err.Number <> 0 And Err.Number = -2147024893 Then
'MsgBox "Missing Path at row # " & i
Sheet1.Cells(i, "AQ").Value = "File has NOT been sent"
On Error GoTo -1
GoTo skip
End If
.Display 'DELETE THIS LINE IF USING SEND
'.send
End With
Sheet1.Cells(i, "AQ").Value = "File has been sent succesfully"
skip:
Set OutMail = Nothing
Set OutApp = Nothing
'End If
Next i
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub
Bookmarks