×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Outlook vba code search keywords and give warning before sending email

Outlook vba code search keywords and give warning before sending email

Outlook vba code search keywords and give warning before sending email

(OP)
I would like to have a warning messagebox if the email body contains specific words before sending an email in outlook.
I have no clue where to start. Any advice is welcome please.

RE: Outlook vba code search keywords and give warning before sending email

This place could be a good starting point.... smile


---- Andy

There is a great need for a sarcasm font.

RE: Outlook vba code search keywords and give warning before sending email

If you are doing this just for yourself and a few words, you could do something like this. Worked for me. But you will have to lighten up your macro security settings in trust center.
In the ThisOutlookSeesion module

CODE -->

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
 Dim FoundWords As String
 Dim Body As String
 Dim MailItem As Outlook.MailItem
 Dim BadWords As Collection
 Dim i As Integer
 If TypeOf Item Is Outlook.MailItem Then
   Set MailItem = Item
   Body = MailItem.Body
   Set BadWords = GetWords
   For i = 1 To GetWords.Count
     If InStr(Body, GetWords(i)) <> 0 Then
       FoundWords = FoundWords & ", " & GetWords(i)
     End If
   Next i
   If Not FoundWords = "" Then
     prompt = "Are you sure you want to send " & Item.Subject & "? It contains: " & FoundWords
     If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
       Cancel = True
     End If
   End If
  End If
End Sub

Public Function GetWords() As Collection
   Dim colWords As New Collection
   'add all your words here
   colWords.Add "Dog"
   colWords.Add "Cat"
   colWords.Add "Money"
   colWords.Add "!@#$"
   '....
   Set GetWords = colWords
End Function 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close