【问题标题】:Add signature with images to the Mail将带有图像的签名添加到邮件
【发布时间】:2014-09-23 15:37:46
【问题描述】:

我有一个 Outlook 宏,我可以在其中创建带有附件的完整邮件,但无法添加保存在 C 盘 (C:\Users\JustinG\AppData\Roaming\Microsoft\Signatures) 中的签名。

签名类型为 .rtf.htm 以及图片。

以下是代码:

Sub Mail_Workbook_1()
    Dim OutApp As Object
    Dim Outmail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set Outmail = OutApp.CreateItem(0)

    On Error Resume Next
   ' Change the mail address and subject in the macro before you run it.
    With Outmail

        .SentOnBehalfOfName = "justin.gatlin@rediffmail.com"
        .To = "abc@xyz.com"
        .CC = ""
        .BCC = ""
        .Subject = "Presentation"
        .Body = "Hi Team,"
        .Attachments.add ("C:\Users\DurshetwarA\Desktop\Excel Examination_Master_V1.xlsx")
        .display
        ''SendKeys ("%s")
    End With
    On Error GoTo 0

    Set Outmail = Nothing
    Set OutApp = Nothing
End Sub

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    在签名目录中的 .htm 文件中,您可以编辑 htm 文件。图片存储为相对路径,当您使用代码时,它会丢失该路径,因此如果您使用离散路径,它将能够找到图片。所以进入文件并寻找任何相对路径并使它们离散。

    "/Microsoft/Signatures/picturefile.jpg"

    将其更改为包含整个路径

    "/root/user/blah blah../Microsoft/Signatures/picturefile.jpg"

    这为我解决了丢失图像的问题。

    【讨论】:

      【解决方案2】:

      Ron de Bruin 描述的解决方案here

      Sub Mail_Outlook_With_Signature_Html_2()
      ' Don't forget to copy the function GetBoiler in the module.
      ' Working in Office 2000-2013
          Dim OutApp As Object
          Dim OutMail As Object
          Dim strbody As String
          Dim SigString As String
          Dim Signature As String
      
          Set OutApp = CreateObject("Outlook.Application")
          Set OutMail = OutApp.CreateItem(0)
      
          strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
                    "Please visit this website to download the new version.<br>" & _
                    "Let me know if you have problems.<br>" & _
                    "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
                    "<br><br><B>Thank you</B>"
      
          'Change only Mysig.htm to the name of your signature
          SigString = Environ("appdata") & _
                      "\Microsoft\Signatures\Mysig.htm"
      
          If Dir(SigString) <> "" Then
              Signature = GetBoiler(SigString)
          Else
              Signature = ""
          End If
      
          On Error Resume Next
      
          With OutMail
              .To = ""
              .CC = ""
              .BCC = ""
              .Subject = "This is the Subject line"
              .HTMLBody = strbody & "<br>" & Signature
              .Send    'or use .Display
          End With
      
          On Error GoTo 0
          Set OutMail = Nothing
          Set OutApp = Nothing
      End Sub
      
      
      Function GetBoiler(ByVal sFile As String) As String
      'Dick Kusleika
          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
      

      【讨论】:

        【解决方案3】:

        使用 .htmlbody 代替 .body 并用 HTML 设计您的邮件正文。这是在您的消息中插入图像的唯一方法。没有插入签名的特定选项

        【讨论】:

        猜你喜欢
        • 2011-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-13
        • 2012-03-01
        相关资源
        最近更新 更多