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

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

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.

  1. Option Explicit
  2. Sub NOTIFICATIONS()
  3. Dim OutApp As Object
  4. Dim OutMail As Object
  5. Dim strbody As String
  6. Dim strname As String
  7. Dim strname1 As String
  8. Dim strname2 As String
  9. Dim strEmp As String
  10. Dim previousName As String
  11. Dim nextName As String
  12. Dim emailWS As Worksheet
  13. Dim nameCol As Double
  14. Dim nameCol2 As Double
  15. Dim empCol As Double
  16. Dim lastCol As Double
  17. Dim lastRow As Double
  18. Dim startRow As Double
  19. Dim startCol As Double
  20. Dim r As Double
  21. Dim sigstring As String
  22. Dim Signature As String
  23. Dim empList As String
  24. ' Get work signature
  25. sigstring = Environ("appdata") & "\Microsoft\Signatures\Notifications.htm"
  26. If Dir(sigstring) <> "" Then
  27. Signature = GetBoiler(sigstring)
  28. Else
  29. Signature = ""
  30. End If
  31. Set OutApp = CreateObject("Outlook.Application")
  32. Set emailWS = ActiveSheet
  33. startRow = 2
  34. startCol = 1
  35. nameCol = 3
  36. nameCol2 = 1
  37. empCol = 5
  38. lastRow = emailWS.Cells(emailWS.rows.Count, nameCol).End(xlUp).row
  39. lastCol = emailWS.Cells(1, emailWS.Columns.Count).End(xlToLeft).Column
  40. For r = startRow To lastRow
  41. strname = (emailWS.Cells(r, nameCol2))
  42. strname1 = Trim(Split(emailWS.Cells(r, nameCol2), ",")(1))
  43. strEmp = emailWS.Cells(r, empCol)
  44. If emailWS.Cells(r + 1, nameCol2) <> "" Then
  45. nextName = (emailWS.Cells(r + 1, nameCol2))
  46. Else
  47. nextName = "Exit"
  48. End If
  49. If strname <> previousName Then
  50. previousName = strname
  51. Set OutMail = OutApp.CreateItem(0)
  52. With OutMail
  53. .To = emailWS.Cells(r, 2).value
  54. .Subject = "Please Review Updated Information "
  55. empList = strEmp & "<br>"
  56. strbody = "<Font Face=calibri>Dear " & strname1 & ", <br><br> " & _
  57. "Please review the below."
  58. End With
  59. Else
  60. If InStr(empList, strEmp) = 0 Then
  61. empList = empList & strEmp & "<br>"
  62. End If
  63. End If
  64. If strname <> nextName Then
  65. OutMail.HTMLBody = strbody & "<B>" & empList & "</B>" & "<br>" & Signature
  66. OutMail.send
  67. End If
  68. If emailWS.Cells(r + 1, nameCol2) = "" Then
  69. Exit Sub
  70. End If
  71. Next r
  72. Set OutMail = Nothing
  73. Set OutApp = Nothing
  74. End Sub
  75. Function GetBoiler(ByVal sFile As String) As String
  76. Dim fso As Object
  77. Dim ts As Object
  78. Set fso = CreateObject("Scripting.FileSystemObject")
  79. Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
  80. GetBoiler = ts.ReadAll
  81. ts.Close
  82. 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:

确定