Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    May 2003
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Capturing the send event (Outlook XP)

    Hello, I am new to Outlook programming. I want to display a form when the user presses send in Outlook. What event is that? Is there an AutoSend event?

    Also, how do I refer to the current e-mail in Outlook. Is there an ActiveItem property, as in Word there is the Activedocument property?

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capturing the send event (Outlook XP)

    The Outlook Application object has an ItemSend event. You can handle it as follows:
    Switch to the Visual Basic Editor (Alt+F11).
    Make sure that the Project Explorer is visible (Ctrl+R).
    Expand Microsoft Outlook Objects.
    Double click ThisOutlookSession.
    Select Application from the Object dropdown list in the module that appears.
    You'll get the "skeleton" for the ItemSend event procedure:

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

    End Sub

    Item is a reference to the mail being sent; you can inspect its Subject property, for instance.
    Cancel is False by default, but you can set it to True to prevent the item from being sent.

    Example (more or less from the online help):

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If MsgBox("Are you sure you want to send " & Item.Subject & "?", _
    vbYesNo + vbQuestion, "Sample") = vbNo Then
    Cancel = True
    End If
    End Sub

    The "active item" is ActiveInspector.CurrentItem. Be careful, this will raise an error if no item is open, so you must test if it is Nothing:

    If Not (ActiveInspector.CurrentItem Is Nothing) Then
    MsgBox ActiveInspector.CurrentItem.Subject
    End If

  3. #3
    2 Star Lounger
    Join Date
    May 2003
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capturing the send event (Outlook XP)

    Hans,

    Many thanks - that worked. Now I need to know how to save and distribute the code.
    The template with the code is saved as
    COCUMENTS and SETTINGS<USERNAME>APPLICATION DATAMICROSOFTOUTLOOKvbaproject.otm.

    Is it possible to save it to another location? with another name? In Word, there is a startup folder, is there something like this in Outlook?

    Thanks.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capturing the send event (Outlook XP)

    It is not really possible to distribute "ordinary" Outlook modules, since Outlook only uses the one VbaProject.otm; you would have to replace an existing file of that name, thereby destroying existing code.

    If you really want to distribute Outlook code, you must write a COM add-in, but that is not really easy. I can't help you with that, but there are probably other Loungers who can. If you don't receive replies in the next few days, consider posting a request in the VB / VBA forum, with a reference to this thread.

    See OL2002: Managing and Distributing Outlook VBA Projects and the links provided there.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Washington, USA
    Posts
    750
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capturing the send event (Outlook XP)

    Depending on what you want to do with the send event you might be able to put the code in a custom form. Then you distribute the form and don't have to worry about the project file.

  6. #6
    2 Star Lounger
    Join Date
    May 2003
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capturing the send event (Outlook XP)

    I have put the code into a custom form, similar to what Hans suggested. But my problem is how to distribute this form to other people. Do you know of another way (Apart from creating a COM Add-in) ,to distribute a custom form in Outlook without overwriting the vbaproject.otm file?

    Also, if I do have to create a COM Add-in, how do I link it to the SEND event in Outlook?

    I am also wondering how to determine what type of item caused the send event. Is there a way to determine if it was a mailitem, or appointmentitem etc?

    Thanks.

  7. #7
    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: Capturing the send event (Outlook XP)

    > Also, if I do have to create a COM Add-in, how do I link it to the SEND event in Outlook?

    In the code module for the Designer, you set up something like this:

    <pre>Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
    ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
    ByVal AddInInst As Object, custom() As Variant)

    ' set up event handler for new Inspectors
    Call EventSetup
    End Sub</pre>

    In a class module (named, for example, CallOnMe, you have something like this:

    <pre>Public WithEvents OLapp As Application

    Private Sub OLapp_ItemSend(ByVal Item As Object, Cancel As Boolean)
    'your Send code here
    End Sub</pre>

    In a regular code module, you have something like this:

    <pre>Dim OLEvents As New CallOnMe

    Sub EventSetup
    Set OLEvents.OLapp = Outlook.Application</pre>

    In theory, then, when the COM add-in is loaded, Outlook should be all set up to intercept the Send command. But I haven't tested with the Send event.

  8. #8
    5 Star Lounger
    Join Date
    May 2001
    Location
    Washington, USA
    Posts
    750
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capturing the send event (Outlook XP)

    If the code is all in a form then you don't need to worry about a com add-in or the vba project. You just publish the form in a way that others can get at it. If you're on Exchange then one good place is the Organizational Forms library. Notes has something comparable. Public Folders might be an option too. If you're not on one of those, you can do a Save As and send the resulting .OFT file to them. They add it to their personal forms library.

Posting Permissions

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