I am reproducing the macro below. It works ok when the files that i have to mail are in local computer, but when i replace it with a network folder, it does not seem to work.
Please help.
Sub SendMail()
Const strFolder = "\\10.xx.xx.xxx\Form-16A_2016_17\Form-16A Q1 to Q4 FY-2016-17"
Const lngCust = 1
Const lngEmail = 2
Const lngFirstRow = 2
Dim lngRow As Long
Dim lngLastRow As Long
Dim objOL As Object
Dim objMsg As Object
Dim fso As Object
On Error Resume Next
Set objOL = GetObject(Class:="Outlook.Application")
If objOL Is Nothing Then
Set objOL = CreateObject(Class:="Outlook.Application")
If objOL Is Nothing Then
MsgBox "Can't start Outlook", vbCritical
Exit Sub
End If
End If
On Error GoTo ErrHandler
objOL.Session.Logon
lngLastRow = Cells(Rows.Count, lngCust).End(xlUp).Row
Set fso = CreateObject("Scripting.FileSystemObject")
For lngRow = lngFirstRow To lngLastRow
If fso.FileExists(strFolder & Cells(lngRow, lngCust).Value & ".pdf") Then
Set objMsg = objOL.CreateItem(0)
objMsg.Subject = "TDS Certificate Q4 AY 2017-18 " & Cells(lngRow, lngCust).Value
objMsg.Body = "Please find attached the TDS Certificate for Q4 AY 2017-18" & vbCrLf & _
"Regards," & vbCrLf & _
objMsg.To = Cells(lngRow, lngEmail).Value
objMsg.Attachments.Add strFolder & Cells(lngRow, lngCust).Value & ".pdf"
objMsg.Send
End If
Next lngRow
ExitHandler:
Set fso = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, vbCritical
Resume ExitHandler
End Sub