与 Embed picture in outlook mail body excel vba 密切相关
我正在尝试将图像嵌入到 Outlook 电子邮件中。
我正在使用以下代码片段,其中一半是从上面的帖子中窃取的:
Sub PictureEmail()
Dim outApp As New Outlook.Application
Dim OutMail As Object
Dim Attchmnt As String
Dim Signature As String
Dim WB As Workbook
Set WB = ThisWorkbook
Attchmnt = "C:\Users\Blah\Painted_Lady_Migration.jpg"
Set OutMail = outApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = WB.Names("to").RefersToRange.Value2
.CC = WB.Names("cc").RefersToRange.Value2
.BCC = WB.Names("bcc").RefersToRange.Value2
.Subject = WB.Names("Subject").RefersToRange.Value2
.HTMLBody = "<img src=""cid:Painted_Lady_Migration.jpg""height=520 width=750>"
.display
End With
If Attchmnt = "" Then
Else
OutMail.Attachments.Add Attchmnt
End If
On Error GoTo 0
End Sub
但是,在查看生成的电子邮件时,出现错误“无法显示链接的图像。文件可能已被移动、重命名或删除”。
我尝试了几种不同的方法来附加文件,包括:
.HTMLBody = "<img src=" & Chr(34) & "cid:Painted_Lady_Migration.jpg" & Chr(34) & "height=520 width=750>"
我就是无法让它工作>_<
我在某个地方看到名称/文件路径中的空格可以抛出它,所以我用下划线替换了名称中的空格
我忘记/错过了什么愚蠢的事情?
最佳答案
cid
在您附加它时创建,因此您需要在显示/发送它之前执行此操作。
试试这样
Set OutMail = outApp.CreateItem(0)
With OutMail
.To = WB.Names("to").RefersToRange.Value2
.CC = WB.Names("cc").RefersToRange.Value2
.BCC = WB.Names("bcc").RefersToRange.Value2
.Subject = WB.Names("Subject").RefersToRange.Value2
If Attchmnt <> "" Then
.Attachments.Add Attchmnt ' (additional arguments are optional)
.HTMLBody = "<img src=""cid:Painted_Lady_Migration.jpg"" height=520 width=750>"
Else
.HTMLBody = "[no attachment included]"
End If
.Display
End With
关于excel - 如何使用 VBA 将图像嵌入到 Outlook 电子邮件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58617458/