3

I have a macro for Outlook where I can create a complete mail with an attachment but can not add a signature saved in my C drive (C:\Users\JustinG\AppData\Roaming\Microsoft\Signatures).

Signature types are .rtf and .htm with images.

The following is the code:

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
Community
  • 1
  • 1
Justin
  • 31
  • 1
  • 1
  • 2

5 Answers5

4

In the .htm file in the signatures directory you can edit the htm file. The pictures are stored as relative path and when you use the code it looses that path so if you use discrete path it will be able to find the pictures. so go into the file and look for any relative paths and make them discrete.

"/Microsoft/Signatures/picturefile.jpg"

change that to include the whole path

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

This solved the missing image problem for me.

Adavid02
  • 189
  • 1
  • 5
  • 20
0

Solution described here by Ron de Bruin.

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
niton
  • 8,771
  • 21
  • 32
  • 52
0

Go into your .htm file stored via notebook to view its code. Scroll all the way down until you find <v:imagedata src=Microsoft\Signatures\abc.files\image001.png> then update the file path to its full file path instead of the shortened version of it i.e. "C:\Users....\AppData\Roaming\Microsoft\Signatures\abc.files\image001.png".

Once done save and exit.

This fixed it for me.

Jayroot8
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 01 '23 at 07:36
-1

Instead of .body use .htmlbody and design your message body in HTML. This is the only way of inserting image in your message. There is no specific option to insert signatureenter image description here

-3

Similar to the solution posted by Adavid02, here you may find a more detailed explanation.

Mihai
  • 1
  • 1