Solved

VB Script to alert when message sent without attachment in Outlook

Posted on 2012-04-03
5
880 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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