Showing posts with label outlook. Show all posts
Showing posts with label outlook. Show all posts

Tuesday, September 05, 2006

HOW TO: Not forget attachment or subject line using Outlook macro

Background

Following VBA code will remind you if you are sending an email with empty subject line, or when you forget the attachment. It checks mail body for word "attach" and then confirms if something is really attached. If you attachment is missing, it will pop-up a dialog box.

The setup

  1. In your Outlook 2003, invoke Visual Basic Editor, either by pressing Alt+F11, or navigating the menu as "Tools->Macro->Visual Basic Editor"
  2. In the Left hand side "Project" panel, make sure entry named "ThisOutlookSession" is highlighted.
  3. Copy paste the code given below in the Right hand side Panel.
  4. Exit out of VB Editor by either Alt+Q or by navigating the menu item File->Close.
Security
  1. Make sure that the security is set to "High" (Tools->Macro->Security)
  2. The changes we made will NOT work with High security, so we need to "certify" our code, so that it always works.
  3. Invoke "selfcert.exe" from "C:\Program Files\Microsoft Office\OFFICE11\SELFCERT.EXE"
  4. In the dialog that pops up, Type your name.
  5. Go back to Visual Basic Editor (Alt+F11 from Outlook)
  6. Navigate to Tools->Digital Signature.
  7. Click "Choose"
  8. Select your name, Click "OK"
  9. Click "OK" to come out of "Digital Signature" dialog.
  10. Exit out of VB Editor (Alt+Q)
Activating the Macro
  1. Restart your Outlook
  2. When asked about macros, select "Enable Macros"
Test
  1. Try sending an email with empty subject to yourself, to test if everything works.
  2. Type "attach" or "attached" in email body and send email to yourself without actually attaching any file.
.. finally "The Code"

Please refer to my earlier post here

Read more!

Thursday, July 20, 2006

Outlook Macro source code

This post is created only for the code, so that I can keep updating it.
The instructions are in other posts.
I do not take credit for this code. Original code for Attachment reminder available here. I merely combined this with Reminder for missing subject. Similar code is available easily just by Googling.

*Update: Outlook counts files used in Signatures as attachments. see here.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
Dim m As Variant
Dim strBody As String
Dim intIn As Integer, intAttachCount As Integer
Dim x As Integer

intAttachCount = 0

strBody = LCase(Item.Body)
intIn = InStr(1, strBody, "original message")
If intIn = 0 Then
intIn = Len(strBody)
intIn = InStr(1, Left(strBody, intIn), "attach")
If intIn > 0 Then

For x = 1 To Item.Attachments.Count
If LCase(Item.Attachments.Item(x).DisplayName) <> "picture (metafile)" Then
intAttachCount = intAttachCount + 1
End If
Next

If intAttachCount = 0 Then

m = MsgBox("It appears that you mean to send an attachment," & vbCrLf & "but there is no attachment to this message." & vbCrLf & vbCrLf & "Do you still want to send?", vbQuestion + vbYesNo + vbMsgBoxSetForeground)

If m = vbNo Then
Cancel = True
Exit Sub
End If
End If
End If
End If

strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If

End Sub


Read more!