Outlook Macro source code

by Mandar Vaze on July 20, 2006
in Code, Productivity, Tutorials, VBA

  • Share
  • Sharebar
  • Share
  • This post is created only for the code, so that I can keep updating it.
  • The instructions are in the other post.
  • 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

Comments

2 Responses to “Outlook Macro source code”
  1. Paul Williamson says:

    Excellent macro and installation instructions; very much appreciated. Two minor gripes: (1) The longest line of code includes the text “&” when it should simply read &
    (2) Would help of you included caveat re. handling of signature files noted in blog of originator of attachment code in your instructions.

  2. desipenguin says:

    Paul: Thanks for kind words. #1 is now fixed. I’ve also updated the post to reflect your second gripe as well. Possible the original post was updated since my post.

Share Your Thoughts