How to Auto Check for Attachments in Specific Outgoing Emails with Outlook VBA

Sometimes, you may forget to add required attachments to specific emails, such as emails to report your weekly works. This article will teach you to activate a popup warning to prevent you from sending the specific emails without attachments.

Unlike Outlook 2010 and previous versions, Outlook 2013 has a native support to remind you when you haven’t attached any files in the outgoing emails. You can enable this feature in Outlook Options like the following screenshot:Auto Warn You If No Attachments in Outlook 2013

As long as you enable the automatic warning for missing attachments, every time when you send an email, a warning will pop up. But most of the time, you indeed don’t need to attach files. In such cases, the warning will be annoying. Here we will tell you how to enable an auto warning when no attachments in specific outgoing emails by means of Outlook VBA.

Auto Check for Attachments in Specific Outgoing Emails

  1. At the very outset, launch Outlook and switch to “Developer” tab.
  2. Click on the “Visual Basic” button in “Code” group.Visual Basic Button
  3. Then in the new popup “Microsoft Visual Basic for Applications” window, you should double click on “ThisOutlookSession” project to open it.
  4. Subsequently, you should copy the following codes into “ThisOutlookSession” project.
Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim strMsg As String
    Dim intAns As Integer
 
    If Item.Class <> olMail Then
       Exit Sub
    End If
 
    'Specify the Email Recipient and Subject
    If InStr(LCase(Item.To), "test") > 0 And InStr(LCase(Item.Subject), "worklog") > 0 Then
       If Item.Attachments.Count = 0 Then
          strMsg = "Do you want to send the email without attachments?"
          intAns = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbExclamation, "Check for Missing Attachments")
          If intAns = vbNo Then
             Cancel = True
          End If
       End If
    End If
End Sub

Copy the Codes in ThisOutlookSession Project

  1. Next click the save icon in the toolbar.
  2. After that, you should proceed to sign this code.
  • First, you should create a digital certificate. MS Office comes packed with a built-in utility – “Digital Certificate for VBA Projects”. You can find it out by searching “vba” in “Start Menu”.Digital Certificates for VBA Projects
  • Next, go back to the “visual basic” window to sign the code.Digital Signature
  1. After that, exit the “Visual Basic” and click “Macro settings” button under the “Developer” tab. In the “Trust Center” dialog, you should select to only enable digitally signed macros. Remember to click “OK” lastly.Change Macro Settings
  2. Finally you can have a try. Create a new message with specific recipient and subject, but without attachments. When you click on “Send” button, you will receive a popup warning, shown as the following picture:Check for Missing Attachments

Keep Your Outlook Data Protected

Since that Outlook is prone to corruptions, you should make efforts to protect your Outlook data. The best way is to make a consistent and up-to-date backup. Hence, you can easily recover corrupted Outlook data from the backups even if suffers unexpected Outlook crash. Additionally, if the backup fail unfortunately, you have no choice but to take aid of an experienced repair tool, like DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair SQL db error and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *