|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
一般情况下,在HTML中用的"<img src=""" & pic & """></img>"链接本地图片文件,发出去对方根本看不到图片。放到附件中又不好看。经过搜索与学习,总算有一个马马虎虎的解决方案,即把图片增加到附件中,然后调用附件中的图片,在正文中显示。(对方如用Outlook收邮件,显示正常,但是网页上的,有些显示还不行),代码如下,
Private Sub Send_Mail() '中文
Dim irow%, i%
Dim myOL As New Outlook.Application
Dim MyMail As Outlook.MailItem
Dim myRecipient As Recipient
Dim pic$, s$
For i = 14 To 26 '签名,放在单元格中
If Len(Cells(i, "i")) Then
If i = 14 Then
s = "<p>" & Cells(i, "i") & "</p>"
Else
s = s & IIf(i = 15, "", "<br>") & Cells(i, "i")
End If
End If
Next
'Debug.Print s
sfilename$ = [i11] '文件的名称,放在单元格中
pic = ThisWorkbook.Path & "\" & sfilename
irow = [b65536].End(xlUp).Row
m = 0
For i = 3 To irow
If Cells(i, "f") <> "已发送" Then
m = m + 1
Set MyMail = myOL.CreateItem(olMailItem)
With MyMail
Set myRecipient = .Recipients.Add(Trim(Cells(i, "b")))
myRecipient.Type = olTo
.SUBJECT = Ssubject
If sfilename = "" Then '假设没有图片的情况下
.HTMLBody = "<Html><body><font size=""3"" face=""Times New Roman"">" & _
"<p>" & Cells(i, "e") & ",</p>" & _
"<p>Merry Christmas!</p>" & _
s & "</font></body></html>"
Else
.Attachments.Add pic '在附件中增加图片位置
.HTMLBody = "<Html><body><font size=""3"" face=""Times New Roman"">" & _
"<p>" & Cells(i, "e") & ",</p>" & _
"<p>Merry Christmas!</p>" & _
"<img id=""_" & sfilename & """ src=""cid:" & sfilname & """>" & s & _
"</font></body></html>"
End If
'用Html方式显示附件中的图片(附在附件中,用其名称对应ID和CID)
If Len([i6]) > 0 Then
Set myRecipient = .Recipients.Add(Trim([i6]))
myRecipient.Type = olCC
End If
.Display
End With
'Cells(i, "f") = "已发送"
Set MyMail = Nothing
Set myRecipient = Nothing
If m = 20 Then GoTo line1
End If
Next
line1:
Set MyContact = Nothing
Set MyNS = Nothing
End Sub
参考资料
" <img width=560 height=420 id="_x0000_i1025"
src="cid:image001.jpg@01C8C4AF.C7E6ED20">"
http://www.cnblogs.com/mqcan/archive/2008/06/02/1212157.html |
|