我在將影像(圖表)插入 HTMLbody 時遇到問題。我將圖表匯出到另一個檔案夾,然后呼叫影像路徑。
msg = "<html>123,<br/> 123 <b>" & countries & ":</b><br/>" & RangetoHTML(tablex) & s & "<img src=""cid:" & fileName & "><html\>"
但是,在我插入帶有上述訊息正文的影像后,它顯示:

通過正確指定哪個影像進行調整后,我得到:

要指定我使用的確切影像:
Set myChart = wbe.Sheets("Sheet1").ChartObjects("Chart 11").Chart
Dim myPicture As String
Dim fileName As String
Dim myPath As String
myPicture = "Chart1.jpg"
myPath = "C:\qwe\"
fileName = myPath & myPicture
myChart.Export fileName
全碼:
Sub transactional_emails()
'Create email and save it as draft
Dim olApp As Object
Dim olMailItm As Object
Dim iCounter As Integer
Dim Dest As Variant
Dim SDest As String
Dim source As String
Dim oAccount As String
Dim msg As String
Dim tablex As Range
Dim wbe As Workbook
Dim las As Long
Dim countries As String
Dim myChart As Chart
countries = "LOL"
Set wbe = Workbooks(ThisWorkbook.Name)
las = wbe.Sheets("Sheet1").Cells(wbe.Sheets("Sheet1").Rows.Count, "A").End(xlUp).Row
Set tablex = wbe.Sheets("Sheet1").Range("A1:G" & las)
With tablex.Borders
.LineStyle = xlContinuous
.Color = vbBlack
.Weight = xlThin
End With
Set myChart = wbe.Sheets("Sheet1").ChartObjects("Chart 11").Chart
Dim myPicture As String
Dim fileName As String
Dim myPath As String
myPicture = "Chart1.jpg"
myPath = "C:\qwe\"
fileName = myPath & myPicture
myChart.Export fileName
'Create the Outlook application and the empty email.
Set olApp = CreateObject("Outlook.Application")
Set olMailItm = olApp.CreateItem(0)
Dim s As String
s = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(s, vbDirectory) <> vbNullString Then s = s & Dir$(s & "*.htm") Else s = ""
s = CreateObject("Scripting.FileSystemObject").GetFile(s).OpenAsTextStream(1, -2).ReadAll
msg = "<html>123,<br/> 123 <b>" & countries & ":</b><br/>" & RangetoHTML(tablex) & s & "<img src=""cid:" & myPicture & """></html>"
With olMailItm
SDest = "[email protected]"
'oAccount = "[email protected]"
.To = SDest
.CC = "[email protected]"
.Subject = countries & " 123 " & Date
.Attachments.Add fileName, 1, 0
.htmlbody = msg
.Save
End With
'Clean up the Outlook application.
Set olMailItm = Nothing
Set olApp = Nothing
End sub
uj5u.com熱心網友回復:
源代碼有效:
- 您將影像附加到 Outlook 中的郵件專案:
.Attachments.Add fileName, 1, 0
- 然后您可以通過以下方式從訊息正文中參考附加影像:
"<img src=""cid:" & myPicture & """>
- 有時候,你還需要設定的
PR_ATTACH_CONTENT_ID屬性(DASL -http://schemas.microsoft.com/mapi/proptag/0x3712001F)上使用附件Attachment.PropertyAccessor。
您還可以考慮添加一些引數,如高度或寬度。請注意,影像名稱不能包含空格。
當您在 Microsoft Office Outlook 中打開包含影像的電子郵件時,可能會阻止影像區域。在無法顯示圖片并在 Outlook文章中顯示為紅色 X 中閱讀更多相關資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/377338.html
標籤:擅长 vba 外表 html-email
上一篇:VBA-比較兩張紙并突出差異
