Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro to paste multiple pictures in the Outlook Email

I have a Qlikview file and I am writting macro to Automate the report generation. I had done the Automation in the form of PowerPoint Presentation. Now I am looking to paste (embed) multiple QV charts in the Outlook email format. I also want to be able to change the position and size of Images.

I am already able to paste one Chart with some text, but now I am looking for pasting multiple charts and formated Text.

sub CreateReport

        Set vOlApp = CreateObject("Outlook.Application")

        Set vMessage = vOlApp.CreateItem(olMailItem)

       

        ActiveDocument.Sheets("Density").Activate

        set image = ActiveDocument.GetSheetObject("CH01")

        ActiveDocument.GetApplication.WaitForIdle

        image.CopyBitmapToClipboard    

        vMessage.GetInspector.WordEditor.Range.Paste

       

        vMessage.Subject = "[MTBF] Report"

        vMessage.To = "Ppp@yahoo.com"

       

        vMessage.Display

end sub

1 Solution

Accepted Solutions
masha-ecraft
Partner - Creator
Partner - Creator

Hi,

This is the code I'm using to paste mulple Qlikview objects into the e-mail

Sub SendMail

Set myApp = CreateObject ("Outlook.Application")
Set myMessage = myApp.CreateItem(olMailItem)
myMessage.BodyFormat = 3 'Outlook.OlBodyFormat.olFormatRichText
Supplier = ActiveDocument.Variables("SelectedSupplier").GetContent.String
myMessage.Subject = Supplier & " / Maksukehotus"
call GetPossibleValues ("E-mail 1","strTo",",")
strTo = ActiveDocument.Variables("strTo").GetContent.String
myMessage.To = strTo

Set myInspector = myMessage.GetInspector 'this inserts signature to e-mail
Set myDoc = myInspector.WordEditor

ActiveDocument.GetSheetObject("TX04").CopyTextToClipboard

myText = ActiveDocument.GetSheetObject("TX04").GetText 'this is needed to calculate the lenght of the iserted text to put the next object after it

myDoc.Range(0,0).Paste 'This pastes at the begining of the message body


ActiveDocument.GetSheetObject("CH06").CopyTableToClipboard true

myDoc.Range(len(myText),len(myText)).Paste 'Pastes after the previous text
' myDoc.Range(myDoc.Characters.Count-1, myDoc.Characters.Count).Paste 'Pastes at the end of the message body
' myMessage.GetInspector.WordEditor.Range.Paste 'Replaces the entire message body with clipboard content

' myInspector.WordEditor.Content.InsertAfter chr(13) 'inserts an empty string at the end of the message body content

myMessage.Display

Set myMessage = Nothing
Set myApp = Nothing
Set myInspector = Nothing
Set myDoc = Nothing

end sub

View solution in original post

14 Replies
Anonymous
Not applicable
Author

I need to do the same thing. Anyone know how to do this? I think the answer is to reposition the cursor in the message body after pasting each image but I can't figure out how to do that.

masha-ecraft
Partner - Creator
Partner - Creator

Hi,

This is the code I'm using to paste mulple Qlikview objects into the e-mail

Sub SendMail

Set myApp = CreateObject ("Outlook.Application")
Set myMessage = myApp.CreateItem(olMailItem)
myMessage.BodyFormat = 3 'Outlook.OlBodyFormat.olFormatRichText
Supplier = ActiveDocument.Variables("SelectedSupplier").GetContent.String
myMessage.Subject = Supplier & " / Maksukehotus"
call GetPossibleValues ("E-mail 1","strTo",",")
strTo = ActiveDocument.Variables("strTo").GetContent.String
myMessage.To = strTo

Set myInspector = myMessage.GetInspector 'this inserts signature to e-mail
Set myDoc = myInspector.WordEditor

ActiveDocument.GetSheetObject("TX04").CopyTextToClipboard

myText = ActiveDocument.GetSheetObject("TX04").GetText 'this is needed to calculate the lenght of the iserted text to put the next object after it

myDoc.Range(0,0).Paste 'This pastes at the begining of the message body


ActiveDocument.GetSheetObject("CH06").CopyTableToClipboard true

myDoc.Range(len(myText),len(myText)).Paste 'Pastes after the previous text
' myDoc.Range(myDoc.Characters.Count-1, myDoc.Characters.Count).Paste 'Pastes at the end of the message body
' myMessage.GetInspector.WordEditor.Range.Paste 'Replaces the entire message body with clipboard content

' myInspector.WordEditor.Content.InsertAfter chr(13) 'inserts an empty string at the end of the message body content

myMessage.Display

Set myMessage = Nothing
Set myApp = Nothing
Set myInspector = Nothing
Set myDoc = Nothing

end sub

Not applicable
Author

Hi Masha,

Yes, this is what I was expecting . Thanks!

Regards

Anonymous
Not applicable
Author

Great, thanks!!!!

Not applicable
Author

Hello! I'm trying to use this code but in my application appears this message in the qlikview's debbuger:

The ActiveX component could not create the 'Outlook.Application' object (this messagem I translated of the portuguese language).

What should I do?

masha-ecraft
Partner - Creator
Partner - Creator

Set Requested Module Security option to 'System Access' and Current Local Security to 'Allow System Access' in QV macro editor.

Anonymous
Not applicable
Author

Check your macro security level.

- Brian

Not applicable
Author

Very nice! thanks a lot!

Not applicable
Author

is there any way to attach a pdf file in email?