Baz*_*Baz 1 email variables excel vba excel-vba
我有一个电子表格,用于跟踪对其他部门的请求.我想要一个宏来生成并发送包含一些预定义文本和一些变量值的电子邮件.我已经有一些工作代码扫描相关的单元格并存储它们的值.
我可以生成电子邮件,我可以打印文本行,包括在主题中插入一个变量,但我似乎无法在电子邮件正文的中间插入任何变量的值.我有以下内容:
Sub IssueRequest()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
' Selecting the last entry in column "B"
Range("B7").Select
ActiveCell.Offset(1, 0).Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
' Collect the unique value to insert into the subject field
Dim Subject As String
Subject = ActiveCell.Value
ActiveCell.Offset(0, 2).Select
' Collect the Part Number for use in the body of the email
Dim PartNumber As String
PartNumber = ActiveCell.Value
' Collect the Quantity for use in the body of the email
ActiveCell.Offset(0, 1).Select
Dim Qty As String
Qty = ActiveCell.Value
'Create the email
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi guys," & vbNewLine & vbNewLine & _
"Please can you issue the following:" & vbNewLine & vbNewLine & _
"Part number: " & vbNewLine & _
"Qty: " & vbNewLine & _
"This is line 4"
On Error Resume Next
With OutMail
.To = "xxxxx.xxxxx@xxxxx-xxxxx.com"
.CC = ""
.BCC = ""
.Subject = Subject
.Body = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub*
Run Code Online (Sandbox Code Playgroud)
我真的需要能够在String strbody的中间插入PartNumber和Qty的值.
strbody = "Hi guys," & vbNewLine & vbNewLine & _
"Please can you issue the following:" & vbNewLine & vbNewLine & _
"Part number: " & PartNumber & vbNewLine & _
"Qty: " & Qty & vbNewLine & _
"This is line 4"
Run Code Online (Sandbox Code Playgroud)
只是包括PartNumber和Qty你在哪里正在创建的电子邮件正文串代码零件内部变量名; 记得使用&运算符将字符串变量连接在一起.
| 归档时间: |
|
| 查看次数: |
25038 次 |
| 最近记录: |