来自 Excel 的 Outlook 嵌入图片未显示在组织外部的邮件中

Outlook embedded picture from Excel not showing in mail outside organisation

我正在使用宏根据 excel 文件撰写报告。该宏使用带有文本的正文和来自预定义 Excel 范围的图片 (png)。 这曾经完美无缺,但现在我必须在组织外部共享报告,我得到的反馈是图像未显示。

有人知道这是不是宏造成的吗? 我也对我的 hotmail 和 gmail 帐户进行了测试,但它也没有显示?

Sub Mail_()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Dim Adm As Worksheet
Dim Body As String
Dim Body2 As String
Dim Body3 As String
Dim Body4 As String
Dim rngToPicture As Range
Dim rng2 As Range
Dim Weeknr As String
Dim strTempFilePath As String
Dim strTempFileName As String
    

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set Adm = ActiveWorkbook.Worksheets("Uit")
Set rngToPicture = Adm.Range("X13:AT65")

Adm.Activate
ActiveWindow.Zoom = 100

strTempFileName = "RangeAsPNG"
              
Weeknr = Adm.Range("AF3").Text
Body = Adm.Range("X6:X6").Text
Body2 = Adm.Range("X8:X8").Text
Body3 = Adm.Range("X9:X9").Text
Body4 = Adm.Range("X11:X11").Text

    

strbody = "<BODY style=font-size:10pt;font-family:Verdana>" & Body & _
"<br><br>" & Body2 & "<br>" & Body3 & "<br><br>" & Body4 & "<br><br>"

'Change only Mysig.htm to the name of your signature
SigString = Environ("appdata") & _
            "\Microsoft\Handtekeningen\Servicekantoor.htm"

    Signature = GetBoiler(SigString)


On Error Resume Next

With OutMail
    .to = "Mailinglist@list.com"
    .CC = ""
    .BCC = ""
    .Subject = "Weekly report " & Weeknr
    
    'Create the range as a PNG file and store it in temp folder
    Call createPNG(rngToPicture, strTempFileName)
  
    'Embed the image in Outlook
    strTempFilePath = Environ$("temp") & "\" & strTempFileName & ".png"
    .Attachments.Add strTempFilePath, olByValue, 0
    .HTMLBody = strbody & "<br><br>" & "<img src='cid:" & strTempFileName & ".png' 
style='border:0'>" & "<br><br>" & Signature
    .Recipients.ResolveAll
     .Display 

End With

On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

你很接近 - src 属性中的 cid 必须不是文件名(外部用户不可见),而是与 [=13= 相匹配的某个值] 属性关于附件:

strTempFilePath = Environ$("temp") & "\" & strTempFileName & ".png"
set Attach = .Attachments.Add(strTempFilePath, olByValue)
Attach.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyCid"
.HTMLBody = strbody & "<br><br>" & "<img src='cid:MyCid' style='border:0'>" & "<br><br>" & Signature