Outlook: Open Form via VBA-Makro and send Mail wit

2019-09-19 18:53发布

问题:

like in the headline I want to open a Form via a Button in the Ribbon of Outlook. This Form contains the MailBody of the selected Mail and some DropDown Fields. When you click on 'Send' there should pop up a MsgBox wich is defined in ThisOutlookSession, but it does not work. When I open the Form manually with the 'Choose Form', it works. Is this a bug, or is there any workaround? Thank you in advance and please ask if anything is not clear.


I use VBA. Under Project1 in ThisOutlookSession I have got following Code:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) MsgBox ("Hallo") End Sub

The Form is stored/published under private forms library and is called from a module with the following code:

Set cstmControls = otlMAPIFolder.Items.Add("IPM.Note.Formular3")

But when I click the Send Button of the Ribbon the MsgBox does not appear.

The full Code of the Module, which calls the Form:

Option Explicit 
Public otlAppl As Outlook.Application
Public otlMAPINameSpace As NameSpace
Public otlMAPIFolder As MAPIFolder
Public otlMailItem As MailItem
Public cstmControls As MailItem
Public cstmUprop As UserProperties

Sub FormSend()
Set otlAppl = CreateObject("Outlook.Application")
Set otlMAPINameSpace = otlAppl.GetNamespace("MAPI")
Set otlMAPIFolder = otlMAPINameSpace.GetDefaultFolder(olFolderInbox)
Set otlMailItem = ActiveExplorer.Selection.Item(1)
Set cstmControls = otlMAPIFolder.Items.Add("IPM.Note.Formular3")
Set cstmUprop = cstmControls.UserProperties

'Body
    Dim strBody As String
    strBody = otlMailItem.Body

'Recipient
Dim strTo As String
    strTo = otlMailItem.SenderEmailAddress

strBody = strBody
With cstmControls
        .To = strTo
        .Body = strBody
        .Display True
    End With


End Sub

回答1:

It looks like the ItemSend event is not fired in Outlook.

Are macros enabled for running? What are the settings for Macro Settings and Programmatic Access in the Trust Center?

Where did you get the Application class?

Use the Application_Startup() event to instantiate your event handling Application object. You can read more about that on the ItemSend not firing for outlook 2010 - Security is Low forum thread.