Friday, February 25, 2005

Never send an email in outlook, without the attachment

How many times have you got an email that says, Oops, you forgot to attach the attachment. Here is a macro that will remedy that. It basically checks your email for the word "attach". If it finds it, then it checks to see if you have an attachment with the email, otherwise, it will prompt you to attach the file. Here are the steps. (1 to 4, show you how to open the VBA script editor; the rest, where to drop the script) 1. Start Outlook 2. Tools | Macros | Security 3. Choose “Medium”, which will prompt you on whether or not you want to run macros (VBA). You may need to restart Outlook at this point in order for that setting to take effect. 4. Tools | Macros | Visual Basic Editor 5. In the Project window (normally on the left of the editor window), goto to the Microsoft Office Outlook Objects tree item. Under this item, you should see the the item "ThisOutlookSession" 6. Double click on the "ThisOutlookSession" item. This should open a code window on the right. 7. The code window will have two drop down bars. 8. Choose Application from the left drop-down bar. and ItemSend from the right drop down bar. 9. Between the lines Private Sub Application_ItemSend(ByVal Item as Object, Cancel as Boolean) and End Sub add the following lines of code. Dim lngres As Long If InStr(1, Item.Subject, "attach") <> 0 Then If Item.Attachments.Count = 0 Then lngres = MsgBox("'Attach' phrase in caption, but no attachments - send anyway?", _ vbYesNo + vbDefaultButton2 + vbQuestion, "Attachment warning") If lngres = vbNo Then Cancel = True End If End If If InStr(1, Item.Body, "attach") <> 0 Then If Item.Attachments.Count = 0 Then lngres = MsgBox("'Attach' phrase in body, but no attachment - send anyway?", _ vbYesNo + vbDefaultButton2 + vbQuestion, "Attachment warning") If lngres = vbNo Then Cancel = True End If End If 10. close the visual basic editor window. 11. test Outlook by sending an email with any word containing attach (attached, attachment, etc), but without attaching anything to the mail. You should get a warning about no attachments being included. (this idea was borrowed from an MSDN blog post that I had seen)

No comments: