Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何在单击“发送”按钮时调用宏?_Vba_Outlook - Fatal编程技术网

Vba 如何在单击“发送”按钮时调用宏?

Vba 如何在单击“发送”按钮时调用宏?,vba,outlook,Vba,Outlook,我有一个宏,它获取我选择的电子邮件的描述,并填充从模板创建的表单的“消息”字段: sText = olItem.Body Set msg = Application.CreateItemFromTemplate("C:\template.oft") With msg .Subject = "Test" .To = "user@user.com" 'Set body format to HTML .BodyFormat = Outlook.OlBodyFormat.olF

我有一个宏,它获取我选择的电子邮件的描述,并填充从模板创建的表单的“消息”字段:

sText = olItem.Body

Set msg = Application.CreateItemFromTemplate("C:\template.oft")
With msg
   .Subject = "Test"
   .To = "user@user.com"
   'Set body format to HTML
   .BodyFormat = Outlook.OlBodyFormat.olFormatHTML
   .HTMLBody = "<HTML><BODY>EmailDesc: " + sText + "</BODY></HTML>"
   .Display
End With

Thx

您需要使用
应用程序\u ItemSend event
,当您按下发送按钮时会触发该事件。您可以在
此Outlook会话模块中创建此事件。您的事件子系统可能如下所示:

EmailDesc: TEST SEND EMAIL BLA BLA BLA..
ComboboxValue: Item1
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error GoTo ErrorHandler

    With Item   'Item is your e-mail
        'this way you could change your subject just before you send message
        .Subject = "test subject"   
        'here some changes regarding body of the message
        .Body = .Body & " Additional text at the end or " & _
                "ComboBoxValue: " '& ... reference to combobox value here
    End With

Exit Sub
ErrorHandler:
    MsgBox "Error!"
End Sub

小心-这将对您的每封电子邮件执行操作,因此您应该添加一些
if语句
,使其仅对您的一些电子邮件有效。

如何获取选定的组合框值?