Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Adding chart & HTML to e-mail

Hi guys, i have the following code

  1. Sub Email_Test
  2. newfile = "C:\Newfile.xls"
  3. EmailBody = "<font face = " & Chr(34) & "Calibri" & Chr(34) & ">Hi, <BR> <BR>" & _
  4.         "<BR> <BR> Please use this link to the new file: <a href=" &_
  5.         Chr(34) & newfile & Chr(34) & ">Click here</a> <BR> </font>"

  6. Set myApp = CreateObject ("Outlook.Application") 
  7. Set myMessage = myApp.CreateItem(olMailItem) 
  8. myMessage.BodyFormat = 2 'HTMLFormat 
  9. myMessage.To = "test@test.com
  10. myMessage.Subject = "New file" 
  11. Set myInspector = myMessage.GetInspector 'add signature to e-mail 
  12. Set myDoc = myInspector.WordEditor 
  13. ActiveDocument.GetSheetObject("CH46").CopyBitmapToClipboard
  14. myDoc.Range(0,0).PasteSpecial False, False, 0, False, 5 
  15. myInspector.WordEditor.Content.InsertBefore chr(13) 
  16. myInspector.WordEditor.Content.InsertBefore chr(13) 
  17. myInspector.WordEditor.Content.InsertBefore EmailBody & chr(13) & chr(13)
  18. myMessage.Display 
  19. Set myMessage = Nothing 
  20. Set myApp = Nothing 
  21. Set myInspector = Nothing 
  22. Set myDoc = Nothing 
  23. End sub



It adds the chart to the body of the e-mail which is great but adds the actual text rather than the html code. Can anyone help me here? I'd like to add the html code and then the chart

1 Solution

Accepted Solutions
Frank_Hartmann
Master II
Master II

try like that:

Sub Email_Test

Set myApp = CreateObject ("Outlook.Application")

Set myMessage = myApp.CreateItem(olMailItem)

    newfile = "C:\Users\Admin\Desktop\123.xlsx"

    myMessage.body = ("EmailBody")

    myMessage.HTMLBODY = "<font face = " & Chr(34) & "Calibri" & Chr(34) & ">Hi, <BR> <BR>" & _

                         "<BR> <BR> Please use this link to the new file: <a href=" &_

                         Chr(34) & newfile & Chr(34) & ">Click here</a> <BR> </font>"

    'myMessage.Attachments.Add("C:\Users\Admin\Desktop\123.xlsx")            'If you want to attach a file

    myMessage.BodyFormat = 2 'HTMLFormat

    myMessage.To = "test@test.com"

    myMessage.Subject = "New file"

    Set myInspector = myMessage.GetInspector 'add signature to e-mail

    Set myDoc = myInspector.WordEditor

    ActiveDocument.GetSheetObject("CH46").CopyBitmapToClipboard

    myDoc.Range(0,0).PasteSpecial False, False, 0, False, 5

    myInspector.WordEditor.Content.InsertBefore chr(13)

    myInspector.WordEditor.Content.InsertBefore chr(13)

    myInspector.WordEditor.Content.InsertBefore EmailBody & chr(13) & chr(13)

    myMessage.Display

    Set myMessage = Nothing

    Set myApp = Nothing

    Set myInspector = Nothing

    Set myDoc = Nothing

End sub

View solution in original post

3 Replies
Frank_Hartmann
Master II
Master II

try like that:

Sub Email_Test

Set myApp = CreateObject ("Outlook.Application")

Set myMessage = myApp.CreateItem(olMailItem)

    newfile = "C:\Users\Admin\Desktop\123.xlsx"

    myMessage.body = ("EmailBody")

    myMessage.HTMLBODY = "<font face = " & Chr(34) & "Calibri" & Chr(34) & ">Hi, <BR> <BR>" & _

                         "<BR> <BR> Please use this link to the new file: <a href=" &_

                         Chr(34) & newfile & Chr(34) & ">Click here</a> <BR> </font>"

    'myMessage.Attachments.Add("C:\Users\Admin\Desktop\123.xlsx")            'If you want to attach a file

    myMessage.BodyFormat = 2 'HTMLFormat

    myMessage.To = "test@test.com"

    myMessage.Subject = "New file"

    Set myInspector = myMessage.GetInspector 'add signature to e-mail

    Set myDoc = myInspector.WordEditor

    ActiveDocument.GetSheetObject("CH46").CopyBitmapToClipboard

    myDoc.Range(0,0).PasteSpecial False, False, 0, False, 5

    myInspector.WordEditor.Content.InsertBefore chr(13)

    myInspector.WordEditor.Content.InsertBefore chr(13)

    myInspector.WordEditor.Content.InsertBefore EmailBody & chr(13) & chr(13)

    myMessage.Display

    Set myMessage = Nothing

    Set myApp = Nothing

    Set myInspector = Nothing

    Set myDoc = Nothing

End sub

Anonymous
Not applicable
Author

Can we add the text and then the chart?

Anonymous
Not applicable
Author

I got it

myDoc.Range(len(EmailBody),len(EmailBody)).Paste

Thanks for your help again!