VBA check email attachments

Source: Internet
Author: User

Recently, I forgot to send attachments to emails. I wrote a VBA applet to check the attachments. If the title (subject) contains a specific string, such as the leave request requested by the Company, time Sheet will check and prompt. It feels quite helpful. The code and steps are as follows.

  1. Open Outlook
  2. Alt + F11 enter code editing mode
  3. Add the code to the thisoutlooksession module and save it.
The code for the image is as follows:
Private sub application_itemsend (byval item as object, cancel as Boolean) 'pops up a reminder if the word "attach? ± Is found but there is no attachment on your email. dim M as variantdim strbody as stringdim intin as longdim intattachcount as integer, intstandardattachcount as integerdim strtitle as stringdim arrlen as integer 'title check text checkstr = array ("Leave request ", "expense sheet", "timesheet", "Time Sheet", "Attach") dim hasatt as booleanon error goto handleerrorintstandardattachcount = 1' for title checkst Rtitle = lcase (item. subject) arrlen = ubound (checkstr) for I = 0 to arrlen intin = instr (1, strtitle, checkstr (I )) if intin> 0 then hasatt = true intin = 0 next I if hasatt = true then M = msgbox ("You forgot the attachment again! "& Vbcrlf &" there is no attachment to this message. "& vbcrlf &" Do you still want to send? ", Vbquestion + vbyesno + vbmsgboxsetforeground) If M = vbno then cancel = trueend ifhandleerror: If err. number <> 0 then msgbox "Outlook attachment reminder error:" & err. description, vbexclamation, "Outlook attachment reminder error" End ifend sub

You can also add other checks based on your needs.

Reference: http://www.businesshut.com/outlook-macros/outlook-attachment-reminder-macro.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.