如何使用单元格值更改邮件中嵌入图像的宽度和高度

编程入门 行业动态 更新时间:2024-10-11 07:33:22
本文介绍了如何使用单元格值更改邮件中嵌入图像的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试创建一个可以发送带有嵌入图像的邮件的宏,但是我想要自定义图像尺寸,因此我想让宏选择单元格中提到的图像尺寸,即宽度和高度,然后在发送邮件之前对其进行调整。

我还想添加另外2个带有链接的图像,所以当用户点击每个链接时,它们会被分配到相应的页面。但是不能得到相同的代码。请帮助。

我的代码如下

Sub SendMail ) Dim olApp As Object Dim olMail As Object 对于I = 2 To Sheet1.Cells(Rows.Count,设置olApp = CreateObject(Outlook.Application)设置olMail = olApp.CreateItem(olMailItem)$ b $($) b 结束 与olMail .To =细胞(I,2).Value .cc =细胞(I ,3).Value .bcc = Cells(I,4).Value .Subject = Cells(I,5).Value .Body = Cells(I,6).Value 错误简历Next .Attachments.Add单元格(I,7).Value .HTMLBody = .HTMLBody& ; < img src ='image1.jpg'& width = Cells(I,8).Value height = Cells(I,9).Value>< br> .Attachments.Add细胞(I,10).Value 出现错误GoTo 0 .Display 。发送 结束 下一个 设置olMail = Nothing 设置olApp = Nothing MsgBox 邮件成功发送 结束子`

解决方案

引用是罪魁祸首。我会用双引号括起来:

.HTMLBody = .HTMLBody& < img src ='image1.jpg'width =&细胞(I,8).Value& height =&细胞(I,9).Value& >< br>

Hi I am trying to create a Macro which can send mail with embedded image but i want to have customize image dimension hence i want the macro to pick image size i.e width and Height mentioned in cell and resize it before sending a mail.

I also want to add another 2 images with web link attached to it, so that when user click on each link it takes them to it's respective page. But can't get code for same. Please help.

My code is as below

Sub SendMail() Dim olApp As Object Dim olMail As Object For I = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row With ws Set olApp = CreateObject("Outlook.Application") Set olMail = olApp.CreateItem(olMailItem) End With With olMail .To = Cells(I, 2).Value .cc = Cells(I, 3).Value .bcc = Cells(I, 4).Value .Subject = Cells(I, 5).Value .Body = Cells(I, 6).Value On Error Resume Next .Attachments.Add Cells(I, 7).Value .HTMLBody = .HTMLBody & "<img src = 'image1.jpg' " & "width= Cells(I, 8).Value height=Cells(I, 9).Value ><br>" .Attachments.Add Cells(I, 10).Value On Error GoTo 0 .Display .Send End With Next Set olMail = Nothing Set olApp = Nothing MsgBox "Mails Sent Successfully" End Sub`

解决方案

The quoting is the culprit. I would surround with double quotes:

.HTMLBody = .HTMLBody & "<img src = 'image1.jpg' width=""" & Cells(I, 8).Value & """ height=""" & Cells(I, 9).Value & """ ><br>"

更多推荐

如何使用单元格值更改邮件中嵌入图像的宽度和高度

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

发布评论

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

>www.elefans.com

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