将用户表单输入添加到电子邮件VBA代码到电子邮件正文

时间:2016-09-29 10:01:37

标签: excel excel-vba email macros vba

我需要能够从Excel发送电子邮件,但我希望在您按提交后,电子邮件的正文包含来自用户表单的值。

我尝试了不同的东西,但我坚持使用下面的代码。

Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String

Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)

'set Importance
aEmail.Importance = 2
'Set Subject
aEmail.Subject = "TestMailSend"
'Set Body for mail
aEmail.Body = "Campaign Name" & Me.ComboBox5.Value
              "Job Number" & Me.ComboBox4.Value
              "Revenue" & Me.ComboBox3.Value


'send one off to 1 person use this static code
'aEmail.Recipients.Add "E-mail.address-here@ntlworld.com"
aEmail.Recipients.Add "Insert email address here"
'Send Mail
aEmail.Send

1 个答案:

答案 0 :(得分:1)

也许您应该更改以下内容:

'Set Body for mail
aEmail.Body = "Campaign Name: " & Me.ComboBox5.Value & chr(10) & _
              "Job Number: " & Me.ComboBox4.Value & chr(10) & _
              "Revenue: " & Me.ComboBox3.Value

&合并两个值,chr(10)添加换行符,_可以编写多行代码。

HTH;)