Howto: Are you sure? prompt in Outlook
∞ Posted at 5:30 amI had a really bad day at work on Thursday. A client asked me to research something for them regarding Outlook. Ideally they want a server side (Exchange) solution where possible, but given thats not possible, a client side script is necessary. VBScript in Outlook. :-/ Two products I really do not like.
But, what a client wants, a client gets. So I sat down and came up with the simplest way I could think of to achieve what they’re needing. Essentially a prompt that asks them if they’re sure they want to send the email when they click send or press Ctrl-Enter. They use MS Office Outlook 2003 still, but I can see this still being required when they get pushed up to MS Office 2007 in the not too distant future. So it had to work across multiple versions of VBA for multiple versions of MS Office.
I’m not a coder. I code primarily in BASH shell scripts or simple PHP stuff that takes no thought. I haven’t done any real coding since Nick and I used to release an Ezine back in the mid 90s on the local BBS scene. Even then, Nick wrote the content and I packaged it up into a single EXE that allowed people to read it in colour and with MIDI music (this was before MP3 came along.) Kind of like the old ACiD ASCII art ezine that was going around back then.
Anyway. Back to today.
I don’t know VB. In fact, I have not used it… ever. :-/ At least not to my memory. I wouldn’t know where to start, and to be honest, I’m not really sure I want to know either. Hell, I had to lookup how to comment out lines so I could put in the usual disclaimer I put in all code I write for clients. So you’ll have to forgive my surprise that this code actually worked.
So what does it do? Well, it intercepts the Send command in Outlook and asks you if you are really sure you want to send the email. Thats it. Nothing more. No great magic whatever. It just asks if you really want to send the email. :-)
Here it is. If you want to use this function, then consider it officially public domain. :-P
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If MsgBox("Are you sure you want to send the email?", vbYesNo
+ vbQuestion + vbMsgBoxSetForeground, "Send Email?")
= vbNo Then
Cancel = True
End If
End Sub
To add this to your own Outlook client (NOT Outlook Express or Windows Mail) then from inside Outlook press Alt-F11. On the left hand side you’ll see Project1. Expand that out till you see “ThisOutlookSession” and double click on ThisOutlookSession. On the right hand side of the screen, just paste the above function into the window, save it and close the Visual Basic editor.
When you try to send an email, it will now always prompt you to make sure you really want to send the email.
I’ll be looking at getting something along the lines of the Item.To and Item.Subject and parsing those to make things a little more useful. For example, having the prompt show them so you can decide. But ultimately, thats not exactly difficult to do and superfluous to my clients requirements at the moment.
If you can think of a better or easier way to do this, or one that might work server side rather that client side, I’d love to hear about it.
By submitting a comment here you grant Steves Ramblings a perpetual license to reproduce your words and name/web site in attribution. Inappropriate comments will be removed at admin's discretion.
1
On Mar 6 2009 at 9:09 am, War_Pig said;
Kind of makes you wonder why that function doesn’t inherently exist in Outlook? Or maybe it does and we just don’t know about it because we dont use it.
Perhaps this might function better though as an Addin that is added to Outlook through logon scripting rather than direct VBA to ensure that it is always there, even after a profile removal (if they aren’t using roaming) or reinstall of Outlook?
2
On Mar 8 2009 at 8:08 pm, Steve said;
I should probably update this post with the final version that actually goes through and shows you the subject and lists every person you’re sending the email to. Including all those in the To, CC and BCC fields.
Then again, I could just leave it as it is. Its not hard to build on it from there.