Tech Talk by a Kiwi
Howto: Are you sure? prompt in Outlook
In 2009 a client asked me to produce a specific kind of functionality for them in Outlook 2003. I don’t know VBA at all, so it was a very new challenge for me. As much as I was apprehensive at the prospect of this particular task, what a client wants a client gets.
So I sat down and spent some time to come 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 upgrade to MS Office 2007 or 2010 in the future. So it had to work across multiple versions of VBA for multiple versions of MS Office.
I’m not a developer. 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 the problem at hand.
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.
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.
Update: I kept meaning to put a better version of this script online. The above one is simple, but doesn’t really give you an idea of how to customise it further. So here is a better version.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' Script by Stephen Cropp of stevesramblings.com
' Copyright (C) 2009 by Stephen Cropp
'
' This script is released under the terms of the BSD license.
' You can find a summary and text of the license terms at the following website
' http://creativecommons.org/licenses/BSD/
'
' THIS SOFTWARE IS PROVIDED BY STEPHEN CROPP "AS IS" AND ANY EXPRESS OR IMPLIED
' WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
' EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
' INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
' CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
' OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
' OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Dim MsgQuery As String
If TypeOf Item Is Outlook.MailItem Then
MsgQuery = "You are sending this email to :" & vbCr & vbCr
If Item.Recipients.Count > 0 Then
For i = 1 To Item.Recipients.Count
MsgQuery = MsgQuery & vbTab & Item.Recipients(i) & vbCr
Next
End If
MsgQuery = MsgQuery & vbCr & "Are you sure you want to send this email?"
If MsgBox(MsgQuery, vbYesNo + vbQuestion + vbMsgBoxSetForeground, Item.Subject) = vbNo Then
Cancel = True
End If
End If
End Sub
| This entry was posted by Steve on 16 January, 2010 at 11:22 am, and is filed under Code. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.

