Have you missed the IBM Lotus Notes functionality of “Prompt to save mail” for each mail in MS Outlook? Or have you cursed yourself for forgetting to add the attachment before sending that all important mail?
MS Outlook might not have all the functionalities of it’s counterparts but it’s powerful VBA macro engine leaves us to do what we want.
1. Attachment Reminder reminds you when you forget to attach a file to an email—preventing a possibly embarrassing situation with a client or boss.
Once installed, the code scans your new email message for words indicating that you've attached a file—you can change the words in the code . The detection only happens for the latest message in a conversation, skipping the replies and forward portions.
2. Outlook offers only two options while sending mail as seen from the screenshot below,
save all mail to sent items or do not save any mail. We cannot selectively save an selectively save a copy of message to sent items as was possible in Lotus Notes
Prompt to save does exactly what it means. Before sending the email, it will prompt whether to save to sent items or not.
Below is the code that does these two jobs. There are lots of versions floating around so not sure whom the credit should go to for the original code. Have modified it to suit my requirements.
Follow the below steps to install the code
1.) Ensure that Macros are enabled for your Microsoft Office Outlook. Macros don’t work with Microsoft Outlook Express, therefore this setup cannot be achieved with Microsoft Outlook Express.
2.) Ensure that your security level is set to Medium. You can set the security level by clicking on Tools –> Macro –> Security. Set the desired level to Medium.
3.) Traverse through Tools –> Macro –> Visual Basic Editor ( Or press ALT + F11)
4.) Expand Project 1 by clicking on the + sign.
5.) Expand Microsoft Office Outlook Objects.
6.) Double click ThisOutlookSession.
Paste the below code, save and exit.
' this sub needs to be installed in the ThisOutlookSession module
Dim vCancel As Boolean
Dim Msg, Style, Title, Response As String
Private Sub Application_ItemSend(ByVal Item As Object, _
Cancel As Boolean)
vCancel = False
Item.Categories = ""
If Item.Class = olMail Then
Call CheckAttachments(Item)
If vCancel = True Then
Cancel = True
Exit Sub
End If
Call CheckToSave(Item)
If vCancel = True Then
Cancel = True
End If
End If
End Sub
' this sub can be installed anywhere
Sub CheckToSave(objMail As MailItem)
Msg = "Do you want to save a copy of this email?" ' Define message.
Style = vbYesNoCancel + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "Mailbox Control" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
objMail.DeleteAfterSubmit = False
ElseIf Response = vbNo Then ' User chose No.
objMail.DeleteAfterSubmit = True
ElseIf Response = vbCancel Then
vCancel = True
End If
End Sub
Sub CheckAttachments(objMail As MailItem)
Dim InCount, MailBody, MailLength, AttachCount, SignAttachCount
'If you have a picture or vCard in your signature then make SignAttachCount equal to the
'number of files attached in your signature.
SignAttachCount = 0
InCount = 0
MailBody = LCase(objMail.Subject) & LCase(objMail.Body)
'If the message is a reply or forward, then the macro will not search for the strings in the original message.
MailLength = InStr(1, MailBody, "from:")
If MailLength = 0 Then MailLength = Len(MailBody)
'Add lines for every string you want to check.
'Parts of a string can be added as in "attach" will match "attached", "enclose" will match "enclosed"
If InCount = 0 Then InCount = InStr(1, Left(MailBody, MailLength), "attach")
If InCount = 0 Then InCount = InStr(1, Left(MailBody, MailLength), "file")
If InCount = 0 Then InCount = InStr(1, Left(MailBody, MailLength), "enclose")
AttachCount = objMail.Attachments.Count
If InCount > 0 And AttachCount <= SignAttachCount Then
Msg = "Did you intend to attach any file in this mail?" ' Define message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "Missing Attachment" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
vCancel = True
End If
End If
End Sub
On startup, click enable macros, if prompted. You should be all ready to go. Send out a test mail and check. If you have any problems in installing leave a comment.
1 comments:
Excellent !! Would be really helpful for people like me who had to face those situations where i had to stand without an answer at my manager's place when he asked "where is the attachment" after reading my mail which says "Please refer attachment"...and today i came to know that you do VB programming as well.that too stuff like this that stand apart ..unbelievable ! Exellent !
Post a Comment