我正在嘗試通過 excel 發送電子郵件并保留電子郵件簽名我可以將 .body 保存為沒有影像的文本,或者通過 .HTMLbody 插入影像,但這會弄亂文本格式,不知道我如何保留它或在不更改文本格式的情況下插入影像
Sub email()
'Microsoft Outlook XX.X Object Library is required to run this code
'Variable declaration
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
Dim lCounter As Long
Dim signature As String
'Set objects
Set objOutlook = Outlook.Application
'Read details from Excel sheet and draft emails
'You can change the counter as per requirement
'Create a new email item
Set objMail = objOutlook.CreateItem(olMailItem)
objMail.Display
signature = objMail.Body
'To
objMail.To = "[email protected]"
'Cc
objMail.CC = ""
'Subject
objMail.Subject = "subject here"
'Email Body
objMail.Body = "whatever i want" & objMail.Body
objMail.HTMLBody = vbCrLf & "<img src='K:\Capital One\Noting Program and spreadsheets\Admin Controls for automations team\Email signature DO NOT USE\email signature.PNG'>"
'Add Attachment
'objMail.Attachments.Add
'Draft email
objMail.Display
objMail.Send
'Close the object
Set objMail = Nothing
'Show confirmation message to user
MsgBox "Done", vbInformation
End Sub
uj5u.com熱心網友回復:
不要在同一個地方使用Body
andHTMLBody
屬性,或者如果你想保留格式。HTMLBody
允許您添加任何影像,但您需要記住您處理的是有效的 HTML 檔案。<body>
因此,您可以在開始標簽和結束</body>
標簽之間插入影像。
如果需要先獲取添加的簽名,則需要呼叫Display,然后獲取或修改HTMLBody
屬性。
uj5u.com熱心網友回復:
此代碼將使用您在 Outlook 中設定的簽名。
Dim Signature As Variant
With OutMail
'Capture signature block.
.Display
Signature = .HTMLBody
.To = ""
.CC = ""
.Subject = "Build Plan"
.HTMLBody = "Hello George," & "<br><br>" & _
"Please incorporate these numbers into your next build schedule." & "<br>br>" & Signature
.Display 'or .Send
End With
uj5u.com熱心網友回復:
根本不要使用純文本Body
屬性,始終設定HTMLBody
.
請記住,您需要將自己的資料與現有資料(在呼叫HTMLBody
時填充簽名)合并 - 找到字串的位置,找到下一個的位置(以處理帶有屬性的標簽),然后插入您的之后擁有自己的 HTML 。Display
"<body"
">"
<body>
">"
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/473443.html