Eric, thanks for the reply. I was trying to use some code I wrote for
myself (using plain text email) on a coworkers computer and didn't realize
there was a difference in the Body property for HTML messages (his default
mail format). I now realize that I can check the Body of olFormatPlain and
olFormatRichText the same way, but as I'm using Outlook 2003, I can't test
the olFormatUnspecified property. Would it be the same as RTF and Plain, or
should I add another line to the Select Case in my code below. This is my
first program for Outlook, so bear with me if these are stupid questions.
Now that I see others like the code, I'm trying to make it more robust. Is
there anything I'm blatantly missing?
Thanks.
-Jeremy
P.S. - Watch out for word wrap.
'---------------------------------------------------------------------------
------------
' Procedure : Application_ItemSend
' DateTime : 7/05/2004, updated to work with non PlainText on 8/17/2004
' Author : Jeremy Gollehon
' Purpose : Warn on blank Subject line and no attachment with keyword
check.
'---------------------------------------------------------------------------
------------
'
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim bAnswer As Boolean
Dim sBodyText As String
Dim bEmptyBody As Boolean
Dim i As Long
Dim vWordsToCheck(2) As String 'used as keyword list for attachment
checker
'Check for blank subject line.
If Item.Subject = "" Then
bAnswer = MsgBox("This message does not have a subject." & vbNewLine & _
"Do you wish to continue sending anyway?", _
vbYesNo + vbExclamation, "No Subject") = vbNo
End If
'Set Body variable based on message type.
Select Case Item.BodyFormat
Case olFormatHTML
sBodyText = Item.HTMLBody
bEmptyBody = (Item.Body = Chr(160))
Case Else
'olFormatPlain, olFormatRichText, olFormatUnspecified?
sBodyText = Item.Body
bEmptyBody = (Item.Body = "")
End Select
If Not bEmptyBody Then
'Check for attachment keywords.
'Use lowercase keywords.
vWordsToCheck(0) = "attach"
vWordsToCheck(1) = "enclosed"
vWordsToCheck(2) = "here it is"
For i = LBound(vWordsToCheck) To UBound(vWordsToCheck)
If InStr(LCase(sBodyText), vWordsToCheck(i)) > 0 Then
If Item.Attachments.Count = 0 Then
bAnswer = MsgBox("It appears you were going to send an attachment
but nothing is attached." & vbNewLine & _
"Do you wish to continue sending anyway?", _
vbYesNo + vbExclamation, "Attachment Not Found")
= vbNo
End If
End If
Next i
End If
'Cancel sending message if answered yes to either message box.
Cancel = bAnswer
End Sub
----------------------------------------------------------------------------