图像在签名中显示,但通过VBA发送后消失。

huangapple go评论74阅读模式
英文:

Image in Sig Displays but Disappears when Sent via VBA

问题

我有一段代码,可以从Excel创建电子邮件,并使用Ron DeBruin的方法添加签名。它可以正常工作,如果我将它保留为.display,则电子邮件将正确显示,包括图像。我不得不修改Outlook签名位置的.htm文件,以包含图像的完整地址,这也是我在这里学到的。

然而,一旦我将代码更改为.send,收件人说图像是空白的...有一个位置留给它们,但它们是空白的方框。如果我将其设置为发送给自己,图像会正确显示。如果我先显示电子邮件,然后再发送,收件人也会收到图像。但是直接从代码中发送时却不起作用。

是什么原因导致这种情况?您在我的代码中看到错误吗?我已经阅读过使用getinspector可能会有帮助,但我不知道如何做到这一点,或者如果确实是一种修复方法,如何在这里应用它。

另外,我也可以接受图像不在签名中,而是插入到电子邮件的其他地方...甚至只是作为附件,尽管在电子邮件中嵌入更可取。

谢谢。

英文:

I have code that creates emails from Excel, and uses Ron DeBruin's method for adding the signature. It all works, and if I leave it as .display, the emails show up correctly, with the image. I had to modify the .htm file in the Outlook signature location to the full address of the image to make that work, which I learned here as well.

However, once I change the code to .send, the recipients are saying the images are blank...there is a spot for them, but they are blank boxes. If I set it to send to myself, the image arrives correctly. If I display the email first and THEN send, the recipients get the image as well. It just does not work when sending directly from within the code.

What would cause that? Do you see an error in my code? I have read that using getinspector could help but I do not understand how to do that, or how to apply it here if that indeed is a fix.

Also, I am open to not having the image be in the signature. It could just be inserted somewhere in the email...maybe even just an attachment, though embedded in the email is much preferred.

Thank you.

Option Explicit

Sub NOTIFICATIONS()
   Dim OutApp As Object
   Dim OutMail As Object
   Dim strbody As String
   Dim strname As String
   Dim strname1 As String
   Dim strname2 As String
   Dim strEmp As String
   Dim previousName As String
   Dim nextName As String
   Dim emailWS As Worksheet
   Dim nameCol As Double
   Dim nameCol2 As Double
   Dim empCol As Double
   Dim lastCol As Double
   Dim lastRow As Double
   Dim startRow As Double
   Dim startCol As Double
   Dim r As Double
   Dim sigstring As String
   Dim Signature As String
   Dim empList As String
   ' Get work signature
   sigstring = Environ("appdata") & "\Microsoft\Signatures\Notifications.htm"
   
   If Dir(sigstring) <> "" Then
      Signature = GetBoiler(sigstring)
   Else
      Signature = ""
   End If
   
   Set OutApp = CreateObject("Outlook.Application")
   Set emailWS = ActiveSheet
   startRow = 2
   startCol = 1
   nameCol = 3
   nameCol2 = 1
   empCol = 5
   lastRow = emailWS.Cells(emailWS.rows.Count, nameCol).End(xlUp).row
   lastCol = emailWS.Cells(1, emailWS.Columns.Count).End(xlToLeft).Column
   
   For r = startRow To lastRow
      strname = (emailWS.Cells(r, nameCol2))
      strname1 = Trim(Split(emailWS.Cells(r, nameCol2), ",")(1))
      strEmp = emailWS.Cells(r, empCol)
      If emailWS.Cells(r + 1, nameCol2) <> "" Then
         nextName = (emailWS.Cells(r + 1, nameCol2))
      Else
         nextName = "Exit"
      End If
      
      If strname <> previousName Then
         previousName = strname
         Set OutMail = OutApp.CreateItem(0)
         With OutMail
            .To = emailWS.Cells(r, 2).value
            .Subject = "Please Review Updated Information "
            empList = strEmp & "<br>"
            strbody = "<Font Face=calibri>Dear " & strname1 & ", <br><br> " & _
            "Please review the below."
         End With
      Else
         If InStr(empList, strEmp) = 0 Then
            empList = empList & strEmp & "<br>"
         End If
      End If
      
      If strname <> nextName Then
         OutMail.HTMLBody = strbody & "<B>" & empList & "</B>" & "<br>" & Signature
         OutMail.send
      End If
      
      If emailWS.Cells(r + 1, nameCol2) = "" Then
         Exit Sub
      End If
   Next r
   
   Set OutMail = Nothing
   Set OutApp = Nothing
End Sub

Function GetBoiler(ByVal sFile As String) As String
   Dim fso As Object
   Dim ts As Object
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
   GetBoiler = ts.ReadAll
   ts.Close
End Function

答案1

得分: 1

本地签名的HTML引用本地图像。您有责任确保它所引用的图像位于Web服务器上(以便无需调整链接),或者您可以添加图像作为附件,并修改HTML以引用附件中的图像(通过img标签中的cid)。

请参阅https://stackoverflow.com/a/71728029/332059。

英文:

The local signature HTML refers to the local images. It is your responsibility to either make sure the images it refers to are on a web server (so that links do not need to be adjusted) or that you add images as attachments and modify the HTML to refer to the attached images (through cid in the img tag).

See https://stackoverflow.com/a/71728029/332059

huangapple
  • 本文由 发表于 2023年7月13日 00:21:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76672633.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定