Can I do this in a macro?

I would like to have Outlook monitor my mail messages for certain "trigger words" and alert me if they exist after I press "send" and then give me the option to abort the send.  Can I do that somehow?  It doesn't appear that I can do it as part of a rule.

Here is why.  I recently found out that certain emails are "tagged" by my company and copies are automatically forwarded to IT folks if the subject or body contain certain words.  The words are IT related... to give them a a heads up of a potential problem as it heads in an email to the help desk.

I am not sure how I feel about that policy- but I do know there is nothing I can do about it- so I would just like to have a little pop-up or something come up in the event the words "account frozen" appear in a message body I am typing or replying to, etc.  As i mentioned- it would be great if I could then go ahead and still "send" or abort the send altogether.  

Thanks for any ideas on this...
snyperjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
Hello snyperj,

If you can identify a target list of words or phrases then yes what you ask can be done via a macro

Regards,
Chris
0
snyperjAuthor Commented:
I have the words, how do i do the macro please?
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Let me adapt something for the purpose .. i'll post later unless someone else has a solution sooner.

Chris
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Chris BottomleySoftware Quality Lead EngineerCommented:
Okay first off in this outlook session put:

Chris
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    App_ItemSend_4 Item, Cancel
End Sub

Open in new window

0
Chris BottomleySoftware Quality Lead EngineerCommented:
IN a normal code module place:

Chris
Sub App_ItemSend_4(ByVal Item As Object, Cancel As Boolean)
    accountFrozen Item, Cancel
End Sub
 
Sub accountFrozen(ByVal Item As Object, Cancel As Boolean)
Const strkeywords As String = "Account Frozen"
Dim arrKeywords() As String
Dim varKeywords As Variant
Dim dicKeyWords As Object
Dim itm As Variant
Dim saveFolder As MAPIFolder
Dim SendMe As Boolean
 
    arrKeywords = Split(Replace(strkeywords, ", ", ","), ",")
    Set dicKeyWords = CreateObject("scripting.dictionary")
    For Each itm In arrKeywords
        If Not dicKeyWords.Exists(LCase(itm)) Then dicKeyWords.Add LCase(itm), itm
    Next
    varKeywords = dicKeyWords.items     ' Definitely only one set of each keyword
    
    For Each itm In arrKeywords
        If InStr(LCase(Item.subject), LCase(itm)) > 0 Or InStr(LCase(Item.body), LCase(itm)) > 0 Then
            SendMe = MsgBox("This mail item has the key word(s) >>> " & itm & " <<< within." & vbCrLf & vbCrLf & "Send it anyway ... yes or no", vbYesNo, "Key Word Alert") = vbYes
            If Not SendMe Then Cancel = True
        End If
    Next
 
End Sub

Open in new window

0
Chris BottomleySoftware Quality Lead EngineerCommented:
Do you need a hand with placing the code?

Chris
0
snyperjAuthor Commented:
I hit Alt & F11 to go into VBA.

I clicked on "This Outlook Session" in the project explorer and pasted the first part of your code in the RH pane.

Then back in project explorer I went down to "modules". right clicked and did insert > module and copy and pasted your second bit of code there and saved it.

However, when I then created a mail message, typed 'Account Frozen' in the body- it just 'sent' when I hit 'send-' nothing else occurred... did I miss something?
0
Chris BottomleySoftware Quality Lead EngineerCommented:
MAcros enabled?

Try modifying
Sub App_ItemSend_4(ByVal Item As Object, Cancel As Boolean)
    stop
    accountFrozen Item, Cancel
End Sub

This will force a stop if it enters the macro at all never mind checking teh key words

Chris
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Assuming it does break then F8 to step through the code and see what happens

Chris
0
Chris BottomleySoftware Quality Lead EngineerCommented:
To Check Security:
----------------------

In the application select Tools | Macro | Security
Select Medium
Select OK

Chris
0
snyperjAuthor Commented:
I am using 2007, so I just set  as shown below, it was on "warnings for signed macros..."

Tried it again, no difference.  I will try to step through the code...
2.JPG
0
snyperjAuthor Commented:
It doesn't break.
3.JPG
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Brings us back to thisoutlooksession then ... can you upload an image of the code there?

Chris
0
snyperjAuthor Commented:
Actually, once i restarted Outlook it is working.  I will have to work through the "Potential Security risk...." pop up I will now get every time I open outlook because of the new macro setting- but that is a topic of another post.

Lastly here, how/where can I add additional words and phrases to the code and can I use wildcards  like

"* Frozen"

0
Chris BottomleySoftware Quality Lead EngineerCommented:
Add phrases ...

comma seperated i.e.

Const strkeywords As String = "Account Frozen"
to
Const strkeywords As String = "Account Frozen, The boss is epic, I love lucy"

Wild cards, I think so but it's a bit of a restructure if i'm right let me think.

Chris

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris BottomleySoftware Quality Lead EngineerCommented:
I'm an idiot ... "* frozen" of course is "frozen"!

Chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.