_ = range("smtp_password").Value .Update End With Preparing the body body = "" of If SMTP If > 0 Then errors occurred in body = body & "*SMTP Errors*:" _ past, add header & range("smtp_error").Value & vbNewLine & vbNewLine Error” End If “SMTP followed by the If Len(range("db_error").Value) > 0 Then errors. If MySQL body = body & "*MySQL Errors*:" _ errors occurred & range("db_error").Value & vbNewLine & vbNewLine add them into the End If body. Similarly add If Len(range("chunk_report").Value) > 0 Then the [chunk_report] body = body & Synchronizations*:" _ messages into the & range("chunk_report").Value & vbNewLine & vbNewLine End If body. Compose the With iMsg email. Subject is .To = range("smtp_to").Value the prefix provided .CC = "" .BCC = "" in [smtp_subject] .From = range("smtp_from").Value worksheet cell .Subject = & " " & followed by the Dir(filename) .TextBody = body base name of the .AddAttachment filename file (without the End With path). Send the email, but if there are On Error GoTo Error_Handler_1 errors, process iMsg.Send On Error GoTo 0 them under Error Handler 1. As the errors accumulated in cells [smtp_error], [db_error], and [chunk_report] are range("smtp_error").Value = "" successfully = "" communicated to range("chunk_report").Value = "" Worksheets(1).Protect Password:="" the users, the contents of these Exit Sub cells are cleared. The worksheet is protected and the subroutine ends.
_ = range("smtp_password").Value .Update End With body = "" If > 0 Then body = body & "*SMTP Errors*:" _ & range("smtp_error").Value & vbNewLine & vbNewLine End If If Len(range("db_error").Value) > 0 Then body = body & "*MySQL Errors*:" _ & range("db_error").Value & vbNewLine & vbNewLine End If If Len(range("chunk_report").Value) > 0 Then body = body & Synchronizations*:" _ & range("chunk_report").Value & vbNewLine & vbNewLine End If Preparing the body of If SMTP errors occurred in past, add header “SMTP Error” followed by the errors. If MySQL errors occurred add them into the body. Similarly add the [chunk_report] messages into the body. With iMsg .To = range("smtp_to").Value .CC = "" .BCC = "" .From = range("smtp_from").Value .Subject = & " " & Dir(filename) .TextBody = body .AddAttachment filename End With Compose the email. Subject is the prefix provided in [smtp_subject] worksheet cell followed by the base name of the file (without the path). On Error GoTo Error_Handler_1 iMsg.Send On Error GoTo 0 Send the email, but if there are errors, process them under Error Handler 1. range("smtp_error").Value = "" = "" range("chunk_report").Value = "" Worksheets(1).Protect Password:="" Exit Sub As the errors accumulated in cells [smtp_error], [db_error], and [chunk_report] are successfully communicated to the users, the contents of these cells are cleared. The worksheet is protected and the subroutine ends.