Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 33

Thread: Solved: Send both html signature and body of email together

  1. #1

    Solved: Send both html signature and body of email together

    Hi,

    I have a string variable Body which is defined "eg Please see the attached" and a html signature which is saved down to my C Drive. Both need to be sent in the email but the text body is being either left out or blocked by the html signature. any ideas how to show both?

    Cheers

    Sarah


    [VBA] .Subject = Subject
    .HTMLBody = Body & "<br><br>" & Signature
    .Importance = olImportanceHigh
    .ReadReceiptRequested = False
    [/VBA]

  2. #2
    Anyone any idea how to go about doing the above?

    Cheers

    Sarah

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post a workbook, I for one cannot envisage the problem.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Hi,

    I have attached the code which is run. Basically the file is opened, declared as the attachment and then closed. The email body is then declared and the signature (html) which is saved to C Drive is attached also to the email.

    But the signature seems to be overwriting the body of text and i am unsure how to resolve this.

    kind regards,

    sarah


    [VBA]
    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
    Sub SendMessage()
    Dim SigString As String
    Dim Signature As String
    Dim str_MsgBody As String

    ''Signature to send in Email
    ''==========================
    SigString = "C:\Documents and Settings\" & Environ("username") & "\Application Data\Microsoft\Signatures\MySig.htm"
    Signature = GetBoiler(SigString)

    If Dir(SigString) = "" Then
    MsgBox "No Signature Saved to C Drive to send Emails"
    End If

    Set objOutlook = CreateObject("outlook.application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    str_MsgBody = "Please find the attached mail"
    With objOutlookMsg

    activecell = "Email Addresss"
    Set objOutlookRecip = .Recipients.Add(ActiveCell)
    '' Attach the spreadsheet to the Email
    Workbooks.Open FileName, UpdateLinks:=False
    Set WB = ActiveWorkbook
    .Attachments.Add WB.FullName
    Windows(str_reportname).Close , savechanges:=False

    '' send the message and attachment!!!
    .Subject = Subject
    .HTMLBody = str_MsgBody & "<br><br>" & Signature
    .Importance = olImportanceHigh
    .ReadReceiptRequested = False
    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    Next
    If DisplayMsg Then
    .Display
    Else
    .Send
    End If
    End If
    End With
    Set objOutlook = Nothing

    End Sub[/VBA]

  5. #5
    Hi,

    Anyone have any suggestions re the above? any ideas would be helpful

    Thanks

    Sarah

  6. #6
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Your code works for me (after removing the spare End If line).
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Hi,

    Sorry - i forgot to remove the last endif. The code works ok but if you see that it defines a message str_MsgBody and then a html signature (i.e. your own normal signature at bottom of emails sent which is saved in html format on your C Drive - gerboiler function finds this)


    So when you're sending the email the content should be "please find attached... etc" and then underneath this is your signature.

    But what is happening is taht the signature is being returned but it is not returning the str_MsgBody bit as well.

    if you remove the signature and replace .htmlbody with .body you can see that the str_MsgBody returns as normal.

    Any ideas on how to correct for this?

  8. #8
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    It worked for me exactly as intended, but I have just tried it with Outlook set to use Word as the email editor, and it behaved as you describe. If you have that set, then I guess the obvious answer is not to use Word?
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    What do you have Outlook set to use and how can i change it?

  10. #10
    Is there a way do you know to send the mail without having to change that setting as microsoft word allows you to spell check etc emails

  11. #11
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I think it's to do with the way Word handles the HTML signature. Try changing the .HTMLBody line to this:
    [VBA].HTMLBody = Replace$(Signature, "<BODY>", "<BODY>" & str_MsgBody & "<BR><BR>")
    [/VBA]
    Regards,
    Rory

    Microsoft MVP - Excel

  12. #12
    Hi,

    i tested that with the microsoft word switched on and it does not work for me its only works when i have word off.

  13. #13
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I'm stumped then because that works for me both with and without Word as the email editor. What default format are your emails?
    Regards,
    Rory

    Microsoft MVP - Excel

  14. #14
    Hi,

    I have attached the settings for my mail format in the attachment. I must have something ticked that is blocking the file from being correctly loaded. I have checked my outlook settings and re-run the macro but am still in limbo im afraid.

  15. #15
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    That's the same settings I was testing with, but I guess from that you are using Office 2003? I'm testing on Office XP so there may be a difference between the two there.
    Regards,
    Rory

    Microsoft MVP - Excel

  16. #16
    That would be it - my computer is windows xp but the version of microsoft is 2003. Anyone have any idea how to downgrade the above Replace$ formula? I think its going to be a very long evening for me!

    Thanks for all your help Rory

    Sarah

  17. #17
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    If no-one responds beforehand, I will try and test later on when I get home as I have Office 2003 there (hopefully it's not an Exchange Server issue, as I don't have one of those at home these days!)
    Regards,
    Rory

    Microsoft MVP - Excel

  18. #18
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    In the meantime, this may help: http://www.outlookcode.com/codedetail.aspx?id=615
    Regards,
    Rory

    Microsoft MVP - Excel

  19. #19
    Thanks Rory i appreciate your help. Will check this link out and see if i can fix it up

    sarah

  20. #20
    Hi Rory,

    Still having difficulty with this, if you were able to spot anything else

    Sarah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •