Solved

VB Script to alert when message sent without attachment in Outlook

Posted on 2012-04-03
5
877 Views
Last Modified: 2012-04-04
Chris_Bottomely provided the following code to paste into ThisOutlookSession in VBA to detect the absence of an attachment in a message when the word attach, attachment etc.. was mentioned in the message. It works great on Outlook 2010, but not on Outlook 2007. Can anyone suggest why?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    If InStr(Item.Body, "attach") > 0 Then
        If Item.Attachments.Count < 1 Then
            If MsgBox("The message body mentions an attachment, but none found." & Chr(13) & Chr(10) & "Send anyway?", vbYesNo + vbDefaultButton2 + vbExclamation, "Attachment Missing") = vbNo Then
                Cancel = True
                Item.Move Application.Session.GetDefaultFolder(olFolderDrafts)
            End If
        End If
    End If

End Sub

Open in new window

0
Comment
Question by:snooflehammer
  • 3
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 37805382
The code will work in any version of Outlook.  Are macros enabled in Outlook 2007?
0
 

Author Comment

by:snooflehammer
ID: 37808305
Macros are enabled. I've tried on two installations of Outlook 2007 and nothing happens when a message without an attachment is sent containing the key word. Three Outlook 2010 PCs work fine.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 37808719
Do you know if the code is even firing?  Set a breakpoint in the code and see if it's running at all.  My guess is that it's not.
0
 

Author Comment

by:snooflehammer
ID: 37808763
Sorry, but I'm no coder. How do I set a break point?
0
 

Author Closing Comment

by:snooflehammer
ID: 37808847
Macros were not disabled, in fact, contrary to my previous comment.

Cheers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question