Thursday, March 17, 2005

Don't forget your attachment!


I've been reading on KC on Exchange & Outlook and came across a really cool post on a little macro you can write within Outlook to make sure you don't forget to attach files. The simple version (which of course you can customize to suite your own typing style) is here:

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


Of course you'll have to know where to place this macro

  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. Doubleclick on This Outlook Session on the left, which will open the code window on the right

  6. In the code window, paste the code

  7. Optional: View | Immediate to make the immediate window show up

  8. Put the cursor in the middle of the code you just pasted

  9. Press F5 to run it

And of course, the source of this wonderful macro is KC, and her blog post is here.

1 comments:

Sean Daniel said...

And here is a more verbose version

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