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: 
Not applicable

Macro for exporting sheets and objects as jpg

Hi,

I need to export different sheets and objects as jpg. I have this script today:

sub ExportBitmapToFile
GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
ActiveDocument.Sheets("SH15").ExportBitmapToFile GraphPath & "Ekonomi_Alla.jpg"
end sub


sub ExportBitmapToFile_2
GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
ActiveDocument.Sheets("SH16").ExportBitmapToFile GraphPath & "Ekonomi_Detaljer.jpg"
end sub


sub ExportBitmapToFile_3
GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
ActiveDocument.GetSheetObject("CH115").ExportBitmapToFile GraphPath & "Ekonomi_Totalt.jpg"
end sub

But when this is run (OnPostReload) only the active sheet, or object from active sheet are exported. Can I activate sheet in some way to be able to export things on different sheets no matter how the app is saved?

Best regards

 

Torbjörn Ungvall (@Ungvall)

Senior Business Discovery Manager

Advectas AB

1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

Hi,

Try using the same Sub for all three objects, and using WaitForIdle member in addition. The following code works on my end. Note the ExportBitMapToFile for Sheets and ExportEx for charts.

Sub Act

          ActiveDocument.Sheets("SH03").Activate

          ActiveDocument.GetApplication.WaitForIdle

          ActiveDocument.Sheets("SH03").ExportBitMapToFile "SH03.jpg"

 

          ActiveDocument.Sheets("SH02").Activate

          ActiveDocument.GetApplication.WaitForIdle

          ActiveDocument.Sheets("SH02").ExportBitMapToFile "SH02.jpg"

          ActiveDocument.Sheets("SH01").Activate

          Set obj3 = ActiveDocument.GetSheetObject("CH03")

          ActiveDocument.GetApplication.WaitForIdle

          obj3.ExportEx "CH3.jpg", 2

End Sub

Hope that helps.

Miguel

View solution in original post

11 Replies
Miguel_Angel_Baeyens

Hi Torbjörn,

Indeed, you need to activate each sheet before exporting.

For sheet = 1 to 12 Step 1

     sheetno = "SH" & sheet

     ActiveDocument.Sheets(sheetno).Activate

     set t=ActiveDocument.ActiveSheet

     ' Do printing here calling to the functions you already have

     ' Using t.Anything instead of ActiveDocument.Sheets

Next

Hope that helps.

Miguel

Not applicable
Author

Hi and thanks,

I don't get the syntax - I guess not like this:

For sheet = 9 to 11 Step 1

      sheetno = "SH" & sheet
      ActiveDocument.Sheets(sheetno).Activate
      set t=ActiveDocument.ActiveSheet

sub ExportBitmapToFile
GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
t.Anything("SH15").ExportBitmapToFile GraphPath & "Ekonomi_Alla.jpg"
end sub


sub ExportBitmapToFile_2
GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
t.Anything("SH16").ExportBitmapToFile GraphPath & "Ekonomi_Detaljer.jpg"
end sub


sub ExportBitmapToFile_3
GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
t.Anything.GetSheetObject("CH115").ExportBitmapToFile GraphPath & "Ekonomi_Totalt.jpg"
end sub

Next

Best regards

Torbjörn Ungvall (@Ungvall)

Senior Business Discovery Manager

Advectas AB

Miguel_Angel_Baeyens

Hi,

My bad, probably this is closer (although untested) to your needs:

Sub ExportBitmapToFile

     ActiveDocument.Sheets("SH15").Activate

     Set t=ActiveDocument.ActiveSheet

     GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"

     t.ExportBitmapToFile GraphPath & "Ekonomi_Alla.jpg"

End Sub

Sub ExportBitmapToFile_2

     ActiveDocument.Sheets("SH16").Activate

     Set t=ActiveDocument.ActiveSheet

     GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"

     t.ExportBitmapToFile GraphPath & "Ekonomi_Detaljer.jpg"

End Sub

Sub ExportBitmapToFile_3

     '' SHXX is the SH ID where CH115 is

     ActiveDocument.Sheets("SHXX").Activate

     Set t=ActiveDocument.ActiveSheet

     GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"

     t.GetSheetObject("CH115").ExportBitmapToFile GraphPath & "Ekonomi_Totalt.jpg"

End Sub

Hope that helps.

Miguel

Not applicable
Author

Hm - this was a bit strange. I only get the first one, and when I change the order - none...

Sub ExportBitmapToFile_3
      ActiveDocument.Sheets("SH14").Activate
      Set t=ActiveDocument.ActiveSheet
      GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
      t.GetSheetObject("CH115").ExportBitmapToFile GraphPath & "Ekonomi_Totalt.jpg"
End Sub

Sub ExportBitmapToFile
      ActiveDocument.Sheets("SH15").Activate
      Set t=ActiveDocument.ActiveSheet
      GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
      t.ExportBitmapToFile GraphPath & "Ekonomi_Alla.jpg"
End Sub

Sub ExportBitmapToFile_2
      ActiveDocument.Sheets("SH16").Activate
      Set t=ActiveDocument.ActiveSheet
      GraphPath = "X:\Development\Eskilstuna Energi och Miljö AB\Export\"
      t.ExportBitmapToFile GraphPath & "Ekonomi_Detaljer.jpg"
End Sub

Best regards

Torbjörn Ungvall (@Ungvall)

Senior Business Discovery Manager

Advectas AB

Miguel_Angel_Baeyens

Hi,

Try using the same Sub for all three objects, and using WaitForIdle member in addition. The following code works on my end. Note the ExportBitMapToFile for Sheets and ExportEx for charts.

Sub Act

          ActiveDocument.Sheets("SH03").Activate

          ActiveDocument.GetApplication.WaitForIdle

          ActiveDocument.Sheets("SH03").ExportBitMapToFile "SH03.jpg"

 

          ActiveDocument.Sheets("SH02").Activate

          ActiveDocument.GetApplication.WaitForIdle

          ActiveDocument.Sheets("SH02").ExportBitMapToFile "SH02.jpg"

          ActiveDocument.Sheets("SH01").Activate

          Set obj3 = ActiveDocument.GetSheetObject("CH03")

          ActiveDocument.GetApplication.WaitForIdle

          obj3.ExportEx "CH3.jpg", 2

End Sub

Hope that helps.

Miguel

Not applicable
Author

Perfect! Thanks a million...

Not applicable
Author

Hi,

One strange thing with this is that the middle object is not exported correctly.

The tab looks like this:

Before.jpg

But the export:

After.jpg

I have tried in different ways, for example to save the document before hand but with the same result. The thing is that it worked before with a different macro. But I can't use that one here...

Any clues?

Best regards

Torbjörn Ungvall (@Ungvall)

Senior Business Discovery Manager

Advectas AB

jjfabian
Partner - Creator III
Partner - Creator III

Hi Torbjörn,

you're referring to embedded image not showing, right?

Unfortunately I think this is normal behaviour by QlikView, I've experienced it in the same way all the time.

Sure, the exported text strings are the right ones ('qmem://<bundled>/BuiltIn/led_r.png' & 'qmem://<bundled>/BuiltIn/led_g.png' in your case), but that doesn't really help us.

I would also appreciate if there was a solution to this. Enlighten us, qlikcommunity

Best Regards,

Jakob

Not applicable
Author

I also noticed that it works fine from the Edit Module when I test the macro. Then the embedded objects are showing right...

???

Best regards

Torbjörn Ungvall (@Ungvall)

Senior Business Discovery Manager

Advectas AB