Monday, June 4, 2007

Macro to warn you if attachment is missed

I have made such mistakes many a times .. I used to write to my Boss .. Please find the attached file .. But there was no attachment .. hehehehe..

I thought .. better i find a way .. before my Boss finds a way to improve me .. So I went to my best friend google .. and found a Macro .. I have edited it as per my requirement ..

Steps in detail :

In Outlook, go to Tools -> Macros -> Security and select Medium. You'll be prompted if you want to run macros when you start Outlook.

Go to Tools -> Macros -> Visual Basic Editor.

Double-click on 'This Outlook Session' in the left-hand panel.

Paste the following code into the code window:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim lngres As Long
If InStr(1, UCase(Item.Body), "ATTACH") <> 0 Then
If Item.Attachments.Count = 0 Then
lngres = MsgBox("'Attach' in body, but no attachment - send anyway?", _vbYesNo + vbDefaultButton2 + vbQuestion, "Boss wont like it ... You did it again")
If lngres = vbNo Then Cancel = True
End If
End If
End Sub

Press F5 to check the code and make sure it's properly compiled.

Close the code editor and restart Outlook. You should be asked on startup if you want to run macros; select Enable Macros.

Send a test message with "attach" somewhere in the body and no attachment to make sure the script works.

No comments: