excel - 将多行提取到 Outlook 电子邮件
问题描述
我有以下代码,当您突出显示一行并运行宏时,它会打开一封新的 Outlook 电子邮件并将相关数据粘贴到位,让客户知道他们的包裹已被发送。
Sub GalleryTracking()
'This assumes that Outlook is already open to simplify the code
'
'The 'Font Name' and 'Font Size' attributes are variables obtained from the Spreadsheet
Dim OutApp As Object
Dim OutMail As Object
Dim var As Variant: var = Selection.Value
Dim sBody As String
Dim sFontName As String
Dim sFontSize As String
'Set the Font Name and Font Size
sFontName = "Calibri"
sFontSize = "11"
'Get the Email Body from the cell
sBody = "Hey" & " " & var(1, 1) & vbCrLf & vbCrLf & _
"Your item has been dispatched. Please find the tracking details below (Please allow 12hrs for tracking to go live): " & vbCrLf & vbCrLf & _
"consignment number: " & var(1, 26) & vbCrLf & vbCrLf & "Please track here: " & " https://www.tnt.com/express/en_gb/site/shipping-tools/tracking.html?searchType=con&cons=" & var(1, 26) & _
vbCrLf & vbCrLf & _
"IMPORTANT: Please note that when signing for the goods you must ensure you're satisfied with the packaging, if it looks damaged in any way please sign for as 'damaged'.
Please open your parcel with great care, particularly when using a knife to ensure that it does
not cut too deeply into the parcel damaging the item. You must inspect the goods promptly and
relay any issues to us within 24 hours, quoting reference " & var(1, 3) & "." & vbCrLf &
vbCrLf
& _
"Have a great day, very best regards,"
'Replace ASCII NEW LINE with HTML NEW LINE
sBody = Replace(sBody, vbCrLf, "<BR>") 'Converts text body to HTML
sBody = Replace(sBody, vbLf, "<BR>")
sBody = Replace(sBody, vbCr, "<BR>")
'Attempt to create an Outlook object
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Err.Clear
MsgBox "NOTHING DONE. The Outlook Object could not be created from Excel." & vbCrLf & _
"Try again when Outlook is open."
Exit Sub
End If
On Error GoTo 0
'Create the Outlook Mail Object (using the default Email account)
Set OutMail = OutApp.CreateItem(0)
'Grab the Signature
OutMail.Display 'Creates .HTMLbody containing the signature
'Determine the values to be sent
With OutMail
.To = var(1, 6)
.CC = var(1, 13)
.Subject = "Your Order Has Been Dispatched"
'Put New .HTMLbody (containing font information) around sBody (HTML body) and in front of
the signature .HTMLBody
' .HTMLBody = "<p style='font-family:" & Arial & ";13:" & sFontSize & "pt'>" & sBody & "
</p>" & .HTMLBody 'Original - did not compile
sFontName = "Calibri"
sFontSize = "11"
.HTMLBody = "<p style='font-family:" & sFontName & ";font-size:" & sFontSize & "pt'>" &
sBody & "</p>" & .HTMLBody
.Display
'.Send - comment out the 'Display line' if you want to send
End With
'Clear the Object Pointers
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
我们现在将以不同的方式来做这件事,并联系分支并提供一份已派出的物品列表。所以我需要做类似的事情,这样当我突出显示一组行并运行它时,它会显示类似于“以下客户项目已被调度”的内容,然后是客户名称列表、他们的参考和他们的跟踪号. 让我们说这些字段位于 A、B 和 C 列中以使其更容易。
电子邮件地址将类似于上面它位于单元格中的位置,因此如果它可以保留为数据被提取,而不是静态的,那就太好了。
解决方案
推荐阅读
- javascript - 从 JS 对象创建多个反应复选框
- python - 以编程方式在 Windows 桌面上执行上下文菜单功能
- javascript - JavaScript 中的比较运算符
- c++ - 我收到一段代码的警告,但是 bjarne stroustrup 的 c++ 书说它应该是一个错误。这里有什么?
- mysql - 我正在使用 mysqlcommand 在 db 中输入数据,但某些变量已识别,其他变量未识别,请检查代码
- powershell - Test-Path 是否接受相对路径?
- c++ - C++ 模板类仅由 uint8_t 类型崩溃
- javascript - 如何获取由 querySelectorAll() 方法 (javascript) 生成的 DOM 数组的每个元素的索引?
- msys2 - 在 MSYS2 MINGW32 shell 中运行软件构建
- amazon-web-services - 如何在 AWS Lambda C# 中获取环境变量