Body does not appear when sending outlook mails with signature with excel macro

  • Since I am new to the VBA I am trying to structure a code to send email through outlook with the signature.But when I run the below code it displays me only the signature(body does not appear).


    When I use "F8" and check it can be clearly seen that my body appears then signature overwrites it.I tried with a lot of experts' answers but it remains with only the signature or only the body.How do I fix this?


    Code
    1. Option Explicit Sub SendEmailwithsign() Dim objoutApp As Object, objoutmail As Object Dim strbody As String, strSig As String Set objoutApp = CreateObject("outlook.Application") Set objoutmail = objoutApp.CreateItem(0) On Error Resume Next With objoutmail .To = "[email protected]" .CC = "" .Subject = "Test mail" .Recipients.ResolveAll .Display 'body appears until this point' strSig = .Environ("appdata") & "Microsoft\Signatures\bbbb.txt" strbody = "Hello" .body = strbody & strSig 'with this step Body part does not appear but only the signature' End With On Error GoTo 0 Set objoutmail = Nothing Set objoutApp = Nothing End Sub
  • Yesthank you for answering my problem.,i have already tried with these codes not only from Rondebruin but from other sites too.But unfortunately same issue occurs wtever the code I use.I would like to know the root cause for that if you have any clue on that matter.

  • Hello,


    Below is an example ...



    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Like" icon ...just below...in the bottom right corner...:)

  • Hello,


    The title of your thread is

    Quote

    Body does not appear ...


    and in your last message ...

    Quote

    it displays only the body.


    Thanks for your clarification ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Like" icon ...just below...in the bottom right corner...:)

  • Yes you are correct.The problem I am facing is both body and signature do not appear together..the code you privide me gives only the body part.what is happening is if you can press F8 and see first signature appears when it goes through "HTMLbody" part of the code signature suddenly disappears and is overwritten by the body.finaly it remains with only the body.How do I make it to appear both body and signature?

  • Hello,


    Thanks for your explanation ...


    Regarding the problem of the signature in html format..., a couple of remarks :


    1. strSig has to be defined in the html format ... with the extension .html


    2. You have to avoid the signature error with


    Code
    1. ' To avoid a Signature error ...
    2. If Dir(strSig) <> "" Then
    3. Signature = GetBoiler(SigString)
    4. Else
    5. Signature = ""
    6. End If


    which uses the function GetBoiler :


    Code
    1. Private Function GetBoiler(ByVal sFile As String) As String
    2. ' Function needed to extract the HTML signature
    3. Dim FSO As Object
    4. Dim ts As Object
    5. Set FSO = CreateObject("Scripting.FileSystemObject")
    6. Set ts = FSO.GetFile(sFile).OpenAsTextStream(1, -2)
    7. GetBoiler = ts.readall
    8. ts.Close
    9. End Function


    Only after this process you can have your macro changed to show :


    Code
    1. .HTMLBody = strbody & Signature


    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Like" icon ...just below...in the bottom right corner...:)