【问题标题】:Embedding image in email with VBA使用 VBA 在电子邮件中嵌入图像
【发布时间】:2016-08-11 20:47:06
【问题描述】:

下面的代码嵌入了照片但不显示,因为

“该文件可能已被移动、重命名或删除。请确认链接指向正确的文件和位置。”

我知道文件路径是正确的。

Sub mail()

Dim Sig As String

Set myOlApp = CreateObject("Outlook.Application")

LR400 = Columns(1).Find("*", SearchDirection:=xlPrevious).Row

sPath = Environ("appdata") & "\Microsoft\Signatures\Amir Higgs.txt"

For x = 2 To LR400

    If Cells(x, 2) <> "no email" Then

     emails = Cells(x, 1)
    'TheBody1 = "The Parallon Workforce Team" & vbCrLf & vbCrLf & vbCrLf & _
    "Amir Higgs" & vbCrLf & _
    "Accounts Payable Clerk" & vbCrLf & _
    "Parallon Workforce Solutions" & vbCrLf & _
    "1000 Sawgrass Corporate Pkwy, 6th Floor" & vbCrLf & _
    "Sunrise, FL 33323" & vbCrLf & _
    "P:  954-514-1656" & vbCrLf & _
    "www.parallon.com"

    Set myitem = myOlApp.CreateItem(olMailItem)

    With myitem
        .SentOnBehalfOfName = "PARA.WFAdjustments@Parallon.com"
        .To = Cells(x, 2)
        .Subject = Cells(x, 3)
        .Body = TheBody1
        '.CC = ""
        .Attachments.Add emails
        .Attachments.Add "C:\Users\JoeSchmo\Pictures\WF Communications.jpg", olByValue, 0
        .HTMLBody = "<BODY><IMG src=""cid:WF Communications.jpg"" width=200> </BODY>"

        .display

    End With

End If

Next x

Set OutMail = Nothing
Set OutApp = Nothing

End Sub

【问题讨论】:

  • 我已经将该链接用作此代码大部分的参考。 @PeterT
  • @KnowMeNot 您是否注意到该链接使用“单引号”来包装 src 属性?此外,您是否尝试过使用不包含空格的图像名称(以防字符串未正确包装并且 HTML 正在寻找名为“WF”的图像)
  • 尝试为这个"&lt;BODY&gt;&lt;IMG src='cid:WF Communications.jpg'" &amp; "width='200'"&gt; &lt;/BODY&gt;"回复"&lt;BODY&gt;&lt;IMG src=""cid:WF Communications.jpg"" width=200&gt; &lt;/BODY&gt;"

标签: html excel vba outlook


【解决方案1】:

将您的 JPG 文件名更改为一个单词 示例 WF_Communications.jpgWFCommunications.jpg

.Attachments.Add "C:\Users\JoeSchmo\Pictures\WF_Communications.jpg", olByValue, 0
.HTMLBody = "<BODY><IMG src=""cid:WF_Communications.jpg"" width=200> </BODY>"

【讨论】:

  • 感谢您的帮助
  • 谢谢,这确实有效,而且非常简单!
  • 只需要使用 1,0 而不是 olByValue, 0
猜你喜欢
  • 2015-02-17
  • 2020-05-28
  • 1970-01-01
  • 2011-03-01
  • 1970-01-01
  • 2011-10-06
  • 2015-01-29
相关资源
最近更新 更多