|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 lim5200 于 2013-11-28 21:48 编辑
各位大师,我在编写用VBA发邮件时碰到一个问题。
我把各个sheet表中的表格截图下来按顺序保存在某一文件夹中,然后在邮件中添加为附件。
我想把这些图片直接在邮件正文中显示出来要怎么办?
如果只有一张的话可以解决。但是要把多张图片都显示出来怎么办?
请大家不吝赐教。谢谢!
Sub test()
k = Worksheets.Count
Set OutlookApp = CreateObject("Outlook.Application")
Set MailItem = OutlookApp.CreateItem(0)
MailItem.Subject = "盘点表"
MailItem.To = ""
n = 0
For i = 1 To k
With Sheets(i)
Sheets(i).Activate
n = n + 1
Set Rng = .Range("a1").CurrentRegion
Rng.CopyPicture xlScreen, xlBitmap
.Paste Destination:=.Range("a1")
Set myPic = .Shapes(1)
With .ChartObjects.Add(0, 0, myPic.Width, myPic.Height).Chart
myPic.Copy
.Paste
SaveName = "D:\temp" & n & ".jpg"
.Export SaveName, "JPG"
.Parent.Delete
End With
myPic.Delete
Set myPic = Nothing
Set Rng = Nothing
MailItem.attachments.Add "D:\temp" & n & ".jpg"
End With
Next
MailItem.HTMLBody = "<p class=MsoNormal> 老板:</span>" & _
"<p> 以下盘点表请查阅。谢谢!</span>" & _
"<p></span>"
For l = 1 To n
MailItem.HTMLBody = "<img id=""_" & "temp" & """ src=""cid:" & "temp" & l & ".jpg" & """>"
Next
MailItem.Send
For l = 1 To n
Kill "D:\temp" & l & ".jpg"
Next
End Sub
|
|