Consulting

Results 1 to 5 of 5

Thread: outlook VBA dialog box when sending email

  1. #1

    outlook VBA dialog box when sending email

    Hi everyone,

    I have not found a similar thread though I assume there is something in this forum I could probably use.
    I am familiar with VBA for Excel but not for Outlook.

    I would like to write a script which does the following:
    - when I send an email I want Outlook to fire a dialog box asking a yes/no question (e.g. 'are you sure you entered all correct recipients?')
    When answering YES: send email
    when answering NO: go back to message, don't send yet and allow me to update the required recipients

    I assume this is not too difficult, but as I am not at all familiar with VBA for Outlook, I think this is a much faster way to do this.

    Thanks a lot for your help!

    Best,
    sven

  2. #2
    You would use the itemsend event e.g. put the following in the ThisOutlookSession module.

    Option Explicit
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim Prompt As String
    Prompt = "Are you sure you entered all correct recipients?"
    If MsgBox(Prompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for recipients") = vbNo Then
    Cancel = True
    End If
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Thanks a lot, this surely works very well! My code now reads:

    Option Explicit
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim Prompt As String
    Prompt = "Did you Bcc the study account?"
    If Item.BCC = "" Then
    If MsgBox(Prompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "BCC study account") = vbNo Then
    Cancel = True
    End If
    End If

    End Sub


    However, though this works like a charm when sending emails, I get a runtime error 438 when I create (or reply to) meeting requests etc. I have tried to find a way to overcome this, but without success so far (clicking END solves the problem so there is no real issue as such, but it would be nice if I could prevent runtime errors from happening when I work in my calendar).

    Does anyone know how I can prevent this from happening?

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Check if the item is an email or not
    If Item.Class = olMail Then
    
    stuff to do
    
    End If
    Charlize

  5. #5
    Hello,

    Thanks for all your help, it works almost perfectly.
    The only thing that I notice from time to time is that, when I start up my computer (and Outlook) in the morning, every now and then this macro doesn't seem to fire. This doesn't happen every day (I would say about once every 3 weeks), and I can solve it by going into the VB editor, double click on ThisOutlookSesseion, press save and exit the VB editor.
    Do you know why this happens? Ideally I would like this to work every time when I strat my computer and Outlook, not in 'only' 95% of the time...
    I have looked on the web here and there and found some info relating to initializing handler, but I don't know if this is the answer to my problem (it happens rarely so I have no way of knowing whether everything works because of the 'initialize handler' or because it's not one of those 'bad' days).

    Thanks a lot,
    sven

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •