PDA

View Full Version : Check if Attachments was added



leogranja
09-13-2017, 09:05 AM
Guys,

I have a code that sends emails to me. I would like to check (by counting) if any of the emails doesn't have attachments. I have tried as below but it didn't work. Can you help me, please?



For Each celly In Sheets("VENDAS CONSOLIDADAS").Range("T10:T127")
If celly <> "" Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set myAttachments = OutMail.Attachments
With Application
.EnableEvents = False
.ScreenUpdating = False
End With


anexo = ThisWorkbook.Path & "\" & Sheets("VENDAS CONSOLIDADAS").Range("U2").Value & "\" & celly.Offset(0, 1).Value & ".pdf"


On Error Resume Next
With OutMail
.display
StrSig = .HTMLbody
.To = Endereco
.CC = Endereco2
.BCC = ""
.Subject = Titulo
.HTMLbody = "<FONT FACE=Calibri (Corpo)>" & StrBody & StrSig
myAttachments.Add anexo
if Item.Attachments.Count = 0 Then
attachcount = attachcount + 1
.display
End With

Thank you very much.

Kenneth Hobs
09-13-2017, 12:09 PM
Welcome to the forum!

If .Add is used, just add 1 to the count.

leogranja
09-13-2017, 02:41 PM
Welcome to the forum!

If .Add is used, just add 1 to the count.

Thanks for welcoming me.

Sorry, but i didn't get it. Could you please write the code?

Kenneth Hobs
09-13-2017, 03:03 PM
myAttachments.Add anexo
attachcount = attachcount + 1