Results 1 to 9 of 9
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Create Mail Event (XP)

    Hi
    How can I capture the event when a new mail item is created in VBA for outlook?
    I want to be prompted each time I compose new mail to use one of my signatures or none. I just don't know how to capture the event, and therefore refer to the object captured!
    AnyHelpGreatlyAppreciated
    Thanks,

    pmatz

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Create Mail Event (XP)

    Hi,
    I think you want the Application.ItemSend event - it will give you the item and the option to cancel sending if required.
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Mail Event (XP)

    Hi, I am already using this event for another routine, but it isn't what I'm looking for as it is triggered on when the mail is SENT not when it is CREATED.

    Perhaps I will have to write a sib to creat a mail item and assign a toolbar button to that...
    Thanks,

    pmatz

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Create Mail Event (XP)

    To be honest, I don't see the practical difference. The event fires before the item is sent, so you can then add text to your message if required. E.g.:
    <pre>Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim retval
    retval = MsgBox("Do you want to add a sig?", vbYesNoCancel)
    If retval = vbYes Then
    Item.Body = Item.Body & vbCrLf & "Regards," & vbCrLf & "Rory"
    ElseIf retval = vbCancel Then
    Cancel = True
    End If
    End Sub
    </pre>


    The same principle applies for adding a signature rather than hardcoded text.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Mail Event (XP)

    Hi, yes I see what you mean. I have been thinking of it as before as I have set signature to be there as a default on a new mail, and wanted to mimck this but have a choices of signatures.

    Obviously the easiest thing is just to write the mail and use the sig icon to apply the signature i desire, but I wanted to see if VBA could prompt me ( in case i forget etc)

    One thing I have found looking at this today is the signatures are not part of the Outlook Object Model, and so am trying to find a way of inserting the signautres without hard coding. I know where they are stored as files, but cannot yet find out how to insert them to the body of the mail.

    Cheers
    Thanks,

    pmatz

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Create Mail Event (XP)

    For the signature, you may want to have a look at this discussion on outlookcode.com which has a lot of good stuff on it.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Mail Event (XP)

    Thats Great, thanks for your help Rory
    <img src=/S/coffeetime.gif border=0 alt=coffeetime width=32 height=48>
    Thanks,

    pmatz

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Create Mail Event (XP)

    You can hook into Outlook creating a new Inspector. The details are a bit complicated, because you are defining your own application-level event. I think I documented most of the bits and pieces in <post#=231866>post 231866</post#>. However, if you've found a better way, please post it!

    Note to self: An example of creating an event in a COM Add-in that overrides normal commandbar control behavior can be found in <post#= 362311>post 362311</post#>.

  9. #9
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Mail Event (XP)

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    I'm very impressed!! That's great - and I can see how it works, yes.

    Thanks man.
    Thanks,

    pmatz

Posting Permissions

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