snyperj
asked on
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...
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...
ASKER
I have the words, how do i do the macro please?
Let me adapt something for the purpose .. i'll post later unless someone else has a solution sooner.
Chris
Chris
Okay first off in this outlook session put:
Chris
Chris
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
App_ItemSend_4 Item, Cancel
End Sub
IN a normal code module place:
Chris
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
Do you need a hand with placing the code?
Chris
Chris
ASKER
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?
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?
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
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
Assuming it does break then F8 to step through the code and see what happens
Chris
Chris
To Check Security:
----------------------
In the application select Tools | Macro | Security
Select Medium
Select OK
Chris
----------------------
In the application select Tools | Macro | Security
Select Medium
Select OK
Chris
ASKER
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
Tried it again, no difference. I will try to step through the code...
2.JPG
ASKER
It doesn't break.
3.JPG
3.JPG
Brings us back to thisoutlooksession then ... can you upload an image of the code there?
Chris
Chris
ASKER
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"
Lastly here, how/where can I add additional words and phrases to the code and can I use wildcards like
"* Frozen"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm an idiot ... "* frozen" of course is "frozen"!
Chris
Chris
If you can identify a target list of words or phrases then yes what you ask can be done via a macro
Regards,
Chris