Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro in Qlikview to control MS Word

Hi All

I need to export charts fropm Qlikview and import them into Word, all from a button in Qlikview.

I've managed to do the exporting of the pictures OK using ExportBitmapToFile, I'm struggling with importing them into Word - here's what I have:

sub RunIt

Set appWord = CreateObject("Word.Application")
Set myDoc = appWord.Documents.Add("C:\Dump\Template Service Line Report.docx")
appWord.Visible = True

If myDoc.Bookmarks.Exists("SLPos") Then
Set rng = myDoc.Bookmarks("SLPos").Range
rng.Select

appWord.Selection.InlineShapes.AddPicture FileName:= "C:\Dump\General Surgery Trust Profitability TrustProf.jpg", LinkToFile:= False, SaveWithDocument:=True


End If
end Sub


It fails on the appWord.Selection.InlineShapes... line, though this works fine when run in word?

Can anyone help?

Thanks

Dominic

1 Solution

Accepted Solutions
Not applicable
Author

Hi

You can probably "butcher" the following code to do what you want, this code takes a full screen copy of the qlikview application, pastes it into a word doc, prints the word doc and then dumps it. I'm sure you can adjust the code that takes a copybitmaptoclipboard to do that only for the objects you're interested in.

SUB mcr_PrintActiveSheet
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Add
Const wdOrientLandscape = 1
objDoc.PageSetup.Orientation = wdOrientLandscape
ActiveDocument.ActiveSheet.CopyBitmapToClipboard false
objWord.Selection.Paste
Const wdAlignParagraphCenter = 1
objDoc.Paragraphs(1).Alignment = wdAlignParagraphCenter
objDoc.PrintOut()
DO WHILE objWord.BackgroundPrintingStatus > 0
LOOP
objWord.Quit wdDoNotSaveChanges
Set objWord = Nothing
Set objDoc = Nothing
END SUB


Hope it helps,

View solution in original post

3 Replies
Not applicable
Author

Hi

You can probably "butcher" the following code to do what you want, this code takes a full screen copy of the qlikview application, pastes it into a word doc, prints the word doc and then dumps it. I'm sure you can adjust the code that takes a copybitmaptoclipboard to do that only for the objects you're interested in.

SUB mcr_PrintActiveSheet
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Add
Const wdOrientLandscape = 1
objDoc.PageSetup.Orientation = wdOrientLandscape
ActiveDocument.ActiveSheet.CopyBitmapToClipboard false
objWord.Selection.Paste
Const wdAlignParagraphCenter = 1
objDoc.Paragraphs(1).Alignment = wdAlignParagraphCenter
objDoc.PrintOut()
DO WHILE objWord.BackgroundPrintingStatus > 0
LOOP
objWord.Quit wdDoNotSaveChanges
Set objWord = Nothing
Set objDoc = Nothing
END SUB


Hope it helps,

Not applicable
Author

Helps a lot. Thanks.

Not applicable
Author

Thanks for Sharing Nigel...