Macro that combines two sheet objects and export as a single image.

    Hi Friends,


    I have come across some questions posted by the community members asking if there is any way to combine 2 or more sheet objects and export them into a single image file.


    While this is not possible directly as Qlikview objects can only be exported one at a time into an output file, there is a workaround available.


    The workaround is to programatically create a container object, load the sheet objects into it in a grid style and export the container object as a picture file. While this idea is not entirely new, I thought I would come up with a working example.


    Please see the attached qvw and let me know if it is of any use for you guys.. Hope that somebody will find it useful.


    In the attached file, I have two sample chart objects and a button. The button has an action that calls a macro that does the following

    • Create a container object
    • Set its style to 2X1 grid
    • Add the two chart objects to the container
    • Call containers export method to export it as a picture into the target file


    Here is the macro code.


    Sub Export




         Call ExportContainer(Chart1,Chart2,TargetFile)

    End Sub



    Sub ExportContainer(Chart1,Chart2,TargetFile)

        set ContainerObj = ActiveDocument.Sheets("Main").CreateContainer

        set ContProp=ContainerObj.GetProperties







        ContProp.ContainedObjects.Item(0).Def.ObjectId = Chart1

        ContProp.ContainedObjects.Item(0).Text.v =Chart1


        ContProp.ContainedObjects.Item(1).Def.ObjectId =Chart1

        ContProp.ContainedObjects.Item(1).Text.v = Chart1

        ContainerObj.SetProperties ContProp


        ContainerObj.ExportBitmapToFile TargetFile


    End Sub



    Please checkout my other blog post

    Loop through a dimension and export a chart into power point