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
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.