如何在单击发送按钮时调用宏? [英] How to call a macro on send button click?

查看:66
本文介绍了如何在单击发送按钮时调用宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a macro that takes the description of an email that I've selected and populates the "message" field of a form that is created from a template:

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

在这个模板中,我有更多的字段需要填写,比如组合框..

In this template, I have more fields to fill, like combobox.. for example.

我想知道,当我点击发送按钮时,我如何获得这个组合的值,并在发送前将其连接到电子邮件的内容?

I would like to know, how do I get the value of this combo when I click on the send button, and concatenate it to the contents of the email before sending?

生成这样的东西:

EmailDesc: TEST SEND EMAIL BLA BLA BLA..
ComboboxValue: Item1

谢谢

推荐答案

您需要使用 Application_ItemSend 事件,它会在您按下发送按钮时触发.您在 ThisOutlookSession 模块 中创建此事件.您的事件子可能如下所示:

You need to use Application_ItemSend event which fires when you press send button. You create this event in ThisOutlookSession module. Your event sub could look like this:

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 语句 以使其仅适用于您的某些电子邮件.

Be careful- this will make action to each of your e-mail therefore you should add some if statements to make it works only with some of your e-mails.

这篇关于如何在单击发送按钮时调用宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆