我有一个宏,它描述了我选择的电子邮件,并填充了从模板创建的表单的"消息"字段:
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
Run Code Online (Sandbox Code Playgroud)
在这个模板中,我有更多的字段要填充,比如组合框.
我想知道,当我点击发送按钮并在发送之前将其连接到电子邮件的内容时,如何获得此组合的值?
生成这样的东西:
EmailDesc: TEST SEND EMAIL BLA BLA BLA..
ComboboxValue: Item1
Run Code Online (Sandbox Code Playgroud)
谢谢
Application_ItemSend event按下发送按钮时需要使用哪个触发.你在中创建这个事件ThisOutlookSession module.您的事件子可能如下所示:
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
Run Code Online (Sandbox Code Playgroud)
小心 - 这将对您的每封电子邮件采取措施,因此您应该添加一些if statements以使其仅适用于您的某些电子邮件.