Need the following code to produce a txt. log on an error, but return the loop interger it was using when the error occured, then retunr to the loop.
Sub email()
Dim OutApp As Object, OutMail As Object
Dim strbody As String
Dim cell As Range
Set cell = Range("J1")
For i = 1 To cell.Value
On Error GoTo errHandler:
strbody =
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
y = "C:\Users\dave.kendall\OneDrive - Christians Against Poverty\Client statements\Output\With Watermark" & Cells(i, 6)
With OutMail
.Display
.Subject = "Christians Against Poverty Client Statement - " & Cells(i, 3)
.Attachments.Add y
.To = Cells(i, 7)
.SentOnBehalfOfName = "dave.kendall@capaust.org"
.HTMLBody = strbody & "
" & .HTMLBody
.Send
End With
'Delete any temp files created
Set OutMail = Nothing
Set OutApp = Nothing
Nexti:
Next i
Exit Sub
errHandler:
Logger "Error", Err.Source, Err.Description
Resume Nexti
End Sub
Sub Logger(sType As String, sSource As String, sDetails As String)
Dim sFilename As String
sFilename = "C:\Users\dave.kendall\OneDrive - Christians Against Poverty\Client statements\Log\logging.txt"
' Open the file to write
Dim filenumber As Variant
filenumber = FreeFile
Open sFilename For Append As #filenumber
Print #filenumber , CStr(Now) & "," & sType & "," & sSource _
& "," & sDetails & "," & Application.UserName
Close #filenumber
End Sub
Sub email()
Dim OutApp As Object, OutMail As Object
Dim strbody As String
Dim cell As Range
Set cell = Range("J1")
For i = 1 To cell.Value
On Error GoTo errHandler:
strbody =
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
y = "C:\Users\dave.kendall\OneDrive - Christians Against Poverty\Client statements\Output\With Watermark" & Cells(i, 6)
With OutMail
.Display
.Subject = "Christians Against Poverty Client Statement - " & Cells(i, 3)
.Attachments.Add y
.To = Cells(i, 7)
.SentOnBehalfOfName = "dave.kendall@capaust.org"
.HTMLBody = strbody & "
" & .HTMLBody
.Send
End With
'Delete any temp files created
Set OutMail = Nothing
Set OutApp = Nothing
Nexti:
Next i
Exit Sub
errHandler:
Logger "Error", Err.Source, Err.Description
Resume Nexti
End Sub
Sub Logger(sType As String, sSource As String, sDetails As String)
Dim sFilename As String
sFilename = "C:\Users\dave.kendall\OneDrive - Christians Against Poverty\Client statements\Log\logging.txt"
' Open the file to write
Dim filenumber As Variant
filenumber = FreeFile
Open sFilename For Append As #filenumber
Print #filenumber , CStr(Now) & "," & sType & "," & sSource _
& "," & sDetails & "," & Application.UserName
Close #filenumber
End Sub