Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
christophebrault
Specialist
Specialist

Macro to generate reports ?

Hi,

I have an application wich present results for many societies.

I have to generate the same report for each society. I have a report working but when i launch it, it create only on PDF with all my societies.

What i want is to generate this report for each value in my field SOCIETY and to record the PDF with each name.

I suppose its possible using macro, but i'm totally newbie a it.

Can you help me ?

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

Hi Christophe,

First, edit your report so it uses each value in the field SOCIETY: Menu Reports, Edit Reports..., Edit >> button, Page menu, Page Settings, Banding tab and click Loop page over possible values in field and select SOCIETY from the drop down. Accept, OK and go to the sheet where you were.

Test that the report is actually banded using this field, do a print preview and note that depending on your report and data volume and possible values of SOCIETY, it may take several minutes.

Once this is working fine when you click on the report, take a look at this macro code or this other macro code and adapt to fit your field names and so. Note that the PDF printer must exist and may differ from the ones used in the snippets of those posts.

Sub ReportPrint

     Set soc = ActiveDocument.Fields("SOCIETY")

     Set socPossible = soc.GetPossibleValues

     For i = 0 to socPossible.Count-1

          soc.Select socPossible.Item(i).Text

          ActiveDocument.GetApplication.WaitForIdle

          ActiveDocument.PrintDocReport "RP01", "Printer Name Here"

     Next

End Sub

Hope that helps.

Miguel

View solution in original post

3 Replies
Miguel_Angel_Baeyens

Hi Christophe,

First, edit your report so it uses each value in the field SOCIETY: Menu Reports, Edit Reports..., Edit >> button, Page menu, Page Settings, Banding tab and click Loop page over possible values in field and select SOCIETY from the drop down. Accept, OK and go to the sheet where you were.

Test that the report is actually banded using this field, do a print preview and note that depending on your report and data volume and possible values of SOCIETY, it may take several minutes.

Once this is working fine when you click on the report, take a look at this macro code or this other macro code and adapt to fit your field names and so. Note that the PDF printer must exist and may differ from the ones used in the snippets of those posts.

Sub ReportPrint

     Set soc = ActiveDocument.Fields("SOCIETY")

     Set socPossible = soc.GetPossibleValues

     For i = 0 to socPossible.Count-1

          soc.Select socPossible.Item(i).Text

          ActiveDocument.GetApplication.WaitForIdle

          ActiveDocument.PrintDocReport "RP01", "Printer Name Here"

     Next

End Sub

Hope that helps.

Miguel

christophebrault
Specialist
Specialist
Author

Yes we are very close to a great solution !

I'm using PDF Creator.

This macro works well but...

When the macro loop, it ask to name each files created. How can you auto name files with the value in the field ?

And then say to save this files in a directory ?

Inscrivez vous à ma Newletter Qlik
DoNotMissQlik- Connect with me on Linkedin
Miguel_Angel_Baeyens

Hi Christophe,

Check the code in this thread, in particular the part that refers to bypass the dialog window. You may consider chaing to another printer (CutePDF instead).

Hope that helps.

Miguel