VBA – How to check messages for specific words before sending them with Outlook

Gmail has the option to revert a message for about 10 seconds after you have sent it:

Well, Outlook with VBA can do similar things, if you are willing to program it a bit with VBA. Let’s say that you are a bad person, who drinks beers and once you drink more than 5, you start sending unpleasant emails to everyone in your mailbox… There are people like this, indeed! ūüôā

While you are sober, you may consider “protecting” yourself from something like this, by introducing an Application_ItemSend¬†event in your own Outlook. It would check every email you send for specific words, and if they are present, it would not allow you to send it. Like this:

The code below checks for the words in the forbiddenWords  array and if it finds anything which is similar to them, it sends the Critical error message and does not allow the email to be sent:

At the end, you get a message, asking you to confirm whether you are willing to send this email or not, although none of the bad words was found. In case that no is selected for an answer, the email is not sent.

If you have noticed that MsgBox  is used once with parenthesis and once without and you realized why this is so, you may pat yourself on the shoulder! Good job!

For everyone else, keep in mind that the MsgBox with parenthesis is a function, which returns a value, equal to vbYes  or vbNo in the second  Select Case part of the code.

Cheers!

Tagged with: , , ,