Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

VB Script to alert when message sent without attachment in Outlook

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
snooflehammer
Asked:
snooflehammer
  • 3
  • 2
1 Solution
 
David LeeCommented:
The code will work in any version of Outlook.  Are macros enabled in Outlook 2007?
0
 
snooflehammerAuthor Commented:
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
 
David LeeCommented:
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
 
snooflehammerAuthor Commented:
Sorry, but I'm no coder. How do I set a break point?
0
 
snooflehammerAuthor Commented:
Macros were not disabled, in fact, contrary to my previous comment.

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now