vba check before sending email if attachment is present

me55a

New Member
Joined
Dec 30, 2017
Messages
5
Greetings,
I found this code online and it's not working for me :( (Outlook 2016)
I have set all macros to allow in the trust center and inserted the code inside Developer-visual basic-this outlook session.
Code:
' Declare a variable to save the body content.
Dim strBody As String
 
' Conver the body content to lowercase.
strBody = LCase(Item.Body)
 
' /* Check if the body contains the keyword "attach". */
If Not strBody Like "*attach*" Then
Exit Sub
End If
 
 
 
' /* Check the number of attachment(s). */
If Item.Attachments.Count = 0 Then
MsgBox "No Attachment currently.", vbExclamation, "Message"
cancel = True
End If
End Sub
Would someone be so kind and tell me if I’m doing it wrong or is there some thing wrong with the code.

Bonus question: If I would like to add multiple “key words” do I separate them with -> ;
Best regards
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Watch MrExcel Video

Forum statistics

Threads
1,099,568
Messages
5,469,457
Members
406,653
Latest member
CBeeker

This Week's Hot Topics

Top