本文介绍了如何使用单元格值更改邮件中嵌入图像的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个可以发送带有嵌入图像的邮件的宏,但是我想要自定义图像尺寸,因此我想让宏选择单元格中提到的图像尺寸,即宽度和高度,然后在发送邮件之前对其进行调整。
我还想添加另外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>"
更多推荐
如何使用单元格值更改邮件中嵌入图像的宽度和高度
发布评论