Solved

VB Script to alert when message sent without attachment in Outlook

Posted on 2012-04-03
5
871 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now