Solved

VB Script to alert when message sent without attachment in Outlook

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
Changing a few Outlook Options can help keep you organized!
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

635 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