Поделиться через


"You forgot to attach the file!"

Yikes, it's been a while since I've posted... and to think for the first 9 months of this blog, I think I posted every single day. I guess I just don't have that much content and I wore it out early... but in reality I think it's more due to my new working arrangement and being more focused when I'm at the office as well as how I am hopelessly addicted to World of Warcraft.

Anyway, a coworker recently gave me an opportunity for a good post. He was complaining about how he sometimes sends an email and forgets to attach a file. It's most embarrassing when he references the attachment in the body of the email, because at least one of the recipients will respond with a "uh... what file?". I told him it would be very simple to perform that check automatically in Outlook, and he challenged me to provide that solution, so here it is, just use the instructions in this article with the following code:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim lngres As Long
If InStr(1, Item.Body, "attach") <> 0 Then
If Item.Attachments.Count = 0 Then
lngres = MsgBox("'Attach' in body, but no attachment - send anyway?", _
vbYesNo + vbDefaultButton2 + vbQuestion, "You asked me to warn you...")
If lngres = vbNo Then Cancel = True
End If
End If
End Sub

This works best if Outlook is your editor. If Word is your editor, the dialog will pop up behind Word, I believe this is a limitation that cannot be worked around when using VBA. There's probably some fancy way to do it in word VBA though, if anyone figures it out, post it as a comment.

The macro isn’t very smart – i.e. it looks for ‘attach’ anywhere in the body, not just in the text you typed. It can easily be extended to do things like warn if you try to send a message with a blank subject, that sort of thing.

Comments

  • Anonymous
    January 01, 2003
    An email with a coworker who was recently acquired and is getting accustomed to Outlook after years with

  • Anonymous
    February 24, 2005
    Chuckles I had to laugh at your intro. I am guessing we are getting more blog postings since you might be like me, you refuse to play until Cosmos is all fixed. ;-)

    I got a blog post for ya, see if you can figure out a way for the language that Wow uses for plug in to attach to a .net webservice I have some other code ready to go. but would be nice for a guild interface to a website using webservices.

  • Anonymous
    February 25, 2005
    Does making the Msgbox System Modal make a difference?

  • Anonymous
    February 25, 2005
    David Horowitz wrote an article called "Did You Forget Something, Again?" in the February 2005 Tech Trax:

    http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=498

    It's very similar to the code above. I implemented it, and within a day I'd saved myself a handful of times. When I forget to use the word "attach", I'm still out of luck.

  • Anonymous
    February 25, 2005
    I think that you are looking for - WinWord as editor:
    vbYesNo + vbDefaultButton2 + vbQuestion + vbSystemModal

    BTW, I'm offering this add-in to all users in the webpage posted.

    Ricardo

  • Anonymous
    March 12, 2005
    Cognitive pyschology has identified a class of errors resulting from the perception of a task being completed causing a final step to be ommitted.

    Other examples include leaving the originals in the copier, your card in the atm, and perhaps even your lights on in the car.

    Read more:
    http://search.msn.com/results.aspx?q=%22post+completion+error%22&FORM=QBRE

  • Anonymous
    March 14, 2005
    The comment has been removed