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
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,377
Messages
6,119,185
Members
448,872
Latest member
lcaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top