简体   繁体   English

嵌入图像并将文件附加到通过Excel VBA发送的电子邮件中

[英]Embedding image in and attaching files to email sent through Excel VBA

I'm writing a piece of code to populate a spreadsheet, then email it out to a bunch of people with the spreadsheet as an attachment, along with an explanatory PDF and an HTML covering letter (featuring the company logo) in the email body. 我正在编写一段代码来填充电子表格,然后将电子表格作为附件通过电子邮件发送给一群人,以及电子邮件正文中的解释性PDF和HTML求职信(带有公司徽标)。

Now, I've sent emails with Excel VBA code before, and I've formatted their layout with HTML in the .HTMLBody . 现在,我之前已经用Excel VBA代码发送了电子邮件,并且在.HTMLBody中用HTML格式化了它们的布局。 But the other bits are causing me some bother. 但是其他的一些让我有些烦恼。

The attachments I think I can figure out; 我认为我可以找出附件; I assume I can just use multiple .Attachments.Add with the various files, haven't tried that. 我假设我可以在多个文件中使用多个.Attachments.Add ,但还没有尝试过。

The main question is the company logo in the email body. 主要问题是电子邮件正文中的公司徽标。 I'm fairly well up on HTML, but I can't figure out how to actually embed a picture when I don't have a src for it. 我对HTML相当了解,但是当我没有src时,我不知道如何实际嵌入图片。

Googling has produced a few approaches, but they've been cid -based and have had comments about only working if the reader uses Outlook. 谷歌搜索产生了一些方法,但是它们是基于cid的,并且仅在读者使用Outlook时才有评论。

Any suggestions? 有什么建议么? Is there a nice simple solution? 有没有很好的简单解决方案?

try the below code, 试试下面的代码,

for attaching the image to your mail(add this under create mail object), 用于将图像附加到您的邮件(在创建邮件对象下添加),

       .Attachments.Add ThisWorkbook.Path & "\image.png"

add this into your mail body (assuming you are using table) 将此添加到您的邮件正文中(假设您正在使用表格)

"<td Colspan=2><img src='cid:image.png' height=205 width=1015></td>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM