如何使用VBA将图像嵌入到Outlook电子邮件中

编程入门 行业动态 更新时间:2024-10-27 20:39:06
本文介绍了如何使用VBA将图像嵌入到Outlook电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

与嵌入紧密相关Outlook邮件正文excel vba中的图片

我正在尝试将图像嵌入到Outlook电子邮件中.

I'm trying to embed an image into an Outlook email.

我正在使用以下代码段,其中一半是从上面的帖子中窃取的:

I'm using the following code snippet, half of which has been stolen from the post above:

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

但是,当查看生成的电子邮件时,出现错误无法显示链接的图像.该文件可能已被移动,重命名或删除".

However, when looking at the generated email, I have the error "The linked image cannot be displayed. The file may have been moved, renamed, or deleted".

我尝试了几种附加文件的方法,包括:

I've tried a few different ways to attach the file, including:

.HTMLBody = "<img src=" & Chr(34) & "cid:Painted_Lady_Migration.jpg" & Chr(34) & "height=520 width=750>"

我只是无法使它工作> _<

I just can't get it to work >_<

我在某处看到名称/文件路径中的空格会引发该错误,所以我用下划线替换了该名称中的空格

I saw somewhere that spaces in the name/filepath can throw it, so I replaced the spaces in the name with underscores

我忘记/错过了什么愚蠢的事情?

What dumb thing am I forgetting/missing?

推荐答案

cid 是在附加时创建的,因此需要在显示/发送它之前执行此操作.

The cid is created when you attach it, so you need to do that before you display/send it.

尝试一下

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

更多推荐

如何使用VBA将图像嵌入到Outlook电子邮件中

本文发布于:2023-11-09 03:05:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   图像   电子邮件   VBA   Outlook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!