Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Code snippet to paste a chart image into outlook email

Hi all,

I have been banging my head against a brick wall for hours now. I can paste a table into a new email message but I now need to paste an image of a chart and I just can't see what syntax to use.

This is my current code...

Dim objOutlk 'Outlook
Dim objMail 'Email item
Dim strMsg
'Create a new message
Set objOutlk = createobject("Outlook.Application")
Set objMail = objOutlk.createitem(olMailItem)
with objMail
.To = MailTo
.subject = ExtraText & MailReport & " at " & YesterdayD & " for " & vstart & " to " & vend
strMsg = vbcrlf & objeMail.gettext & vbcrlf

rem ** copy full table to clipboard **
objReport.CopyTableToClipboard true
.GetInspector.WordEditor.Range.Paste
.GetInspector.WordEditor.Content.InsertAfter strMsg
.Send
end with


I would appreciate some help please.

TIA, Jane

9 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Jane,

I believe you want to use an API called "CopyBitmapToClipboard":

Hee is an example:

ActiveDocument.GetSheetObject("CH01").CopyBitmapToClipboard

good luck!

Oleg

Ask me about Qlik Sense Expert Class!
Not applicable
Author

Hi Oleg,

I am OK with the QlikView bit, its the code to pop it into an email thats doing me in. I know its not strictly QlikView but I thought I would ask 🙂

Cheers,

Jane

Not applicable
Author

The only email image syntax I could get to work was "AddRelatedBodyPart" function. It can paste in an image into the body of the email, I could only get it to work with a single image. Hope this helps.

function sendMail
Dim objEmail
Dim strMailTo

Const CdoReferenceTypeName = 1
Const cdoSendUsingPort = 2 ' Send the message using SMTP
'Const cdoBasicAuth = 1 ' Clear-text authentication
Const cdoTimeout = 60 ' Timeout for SMTP in seconds
'Const cdoPort = 25 ' Port number for SMTP

Const cdoNTLM = 2

'Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay

' Create bitmap of sheet
ActiveDocument.ActivateSheetByID "SH01"
ActiveDocument.Sheets("SH01").ExportBitmapToFile "C:\temp\SH01.png"

'Get Selected values from field "mailto"
Set objSelected = ActiveDocument.Fields("mailto").GetSelectedValues

if objSelected.Count = 0 then ' Nothing Selected
msgbox ("No e-mail reciepient selected")
exit function
else
'Sending mail
Set objEmail = CreateObject("CDO.Message")
Set objConf = objEmail.Configuration
Set objFlds = objConf.Fields

With objFlds
'---------------------------------------------------------------------
' SMTP server details
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = getVariable("mailServer")
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = getVariable("mailServerUsername")
.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = getVariable("mailServerPassword")
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = getVariable("SMTPport")
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cdoTimeout
.Update
'---------------------------------------------------------------------
End With

For i = 0 to objSelected.Count-1 ' create mailTo list
strMailTo = strMailTo & objSelected.item(i).Text & ";"
next

objEmail.MimeFormatted = True
strMailTo = left(strMailTo,len(strMailTo)-1) ' remove the last ; in list
objEmail.To = strMailTo
objEmail.From = "qvadmin@company.com"
objEmail.Subject = getVariable("mailSubject")

'objEmail.HTMLBody = "<html>Check this out: <img src=""cid:report.bmp""></html>"

objEmail.HTMLBody = "<html>Check this out: </html>"
objEmail.AddRelatedBodyPart "C:\TEMP\SH01.png", "SH01.png", CdoReferenceTypeName

objEmail.Send

Set objFlds = Nothing
Set objConf = Nothing
Set objEmail = Nothing
end if
'msgbox ("Mail Sent")
end function

Not applicable
Author

Tom, Thanks so much I will defo give this a try. It's not very easy is it?

All the best,

Jane

Not applicable
Author

I tried this. Doesnt work....

jagan
Partner - Champion III
Partner - Champion III

Hi,

I use the code below to copy the sheet and attach it in the Mail client

For a button i assign three actions

1) Run Macro - CaptureScreen - to save the screenshot of the sheet and save it in C drive.

2) Launch - select you mail client application

3) Run Macro - Insert image in mail

sub CaptureScreen

    ActiveDocument.ActiveSheet.ExportBitmapToFile "C:\Snapshot.PNG"   

    'msgbox "Screen capture is stored in C:\Snapshot.JPG."

end sub

sub InsertImageInMail

    ActiveDocument.GetApplication.Sleep 2000

    Set objShell = CreateObject("WScript.Shell")

    objShell.SendKeys "%FNM" - short cut keys for attachment

    objShell.SendKeys "%IA" --short cut keys for attachment

    objShell.SendKeys "C:\Snapshot.PNG"

    objShell.SendKeys "{ENTER}"

end sub

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

hi jagan

tyvm, i  learn a new function "CaptureScreen"   ha

but not clear your second function “select you mail client application”

how to do that?

Regards,

Lee

jagan
Partner - Champion III
Partner - Champion III

Hi,

Assign an Action to Button, as shown in the screen shot, now select you mail client like Outlook, Lotus Notes etc.

Regards,

Jagan.

Not applicable
Author


Hi Jane ,

can you please share the code to send a table as an object in a mail body through Qlikview Macro .

Need it urgently ,

Help Appreciated

Thanks