I have a macro to email a sheet with a message , which works fine
However, should cell D1 be zero, then sheet must not be attached, an message in body of email to state
"strBody = "Hi " & Sheets("BR1").Range("S1") "& please check your debtors ageing and hand over your problematic debtors for collection" & vbNewLine & vbNewLine &
Sub Email_report()
Dim File As String, strBody As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
File = Environ$("temp") & "\" & Format(Range("Q2"), "mmm-yy ") & Format(Now, "dd-mmm-yy h-mm-ss") & ".xlsx"
strBody = "Hi " & Sheets("BR1").Range("S1") & vbNewLine & vbNewLine & _
"Attached, please find " & Sheets("BR1").Range("A1") & vbNewLine & vbNewLine & _
"Please check attend to your slow paying debtors" & vbNewLine & vbNewLine & _
"Regards" & vbNewLine & vbNewLine & _
"Howard"
ActiveWorkbook.Save
Sheets("BR1").Copy
With ActiveWorkbook
.SaveAs Filename:=File, FileFormat:=51
.Close savechanges:=False
End With
With CreateObject("Outlook.Application").CreateItem(0)
.Display
.to = Join(Application.Transpose(Sheets("BR1").Range("R2:R5").Value), ";")
.Subject = Sheets("Br1").Range("A1")
.body = strBody
.Attachments.Add File
'.Send
End With
Kill File
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
I have attached sample data
Your assistance in this regard is most appreciated
Bookmarks