Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
LKSRCH
Contributor II
Contributor II

Printing Reports by batch

Hello,

I need to find a way to start QV, reload, select the current month and year and then print a report. 

Is there an easy way to do that? Reload is not the problem, but how can I select fields and print reports? 

 

Hope someone can help me.

 

Best regards

Labels (3)
1 Solution

Accepted Solutions
jaibau1993
Partner - Creator III
Partner - Creator III

Hi!

I had a similar issue. I solved it as follows:

First, I created a .bat file that opens the QlikView file and passes a variable:

"C:\Program Files\QlikView\QV.exe"  /vmRunMacro=1  "C:\QV\MacroFromCMD.qvw"

that line opens MacroFromCMD.qvw and sets the variable vmRunMacro (that must be created in the QV file) to value 1.

Secondly, I created an action "On Open" (Settings >> Document Properties >> Triggers >> OnOpen >> Edit Actions). It is a "Run Macro" action that runs the following code:

Sub Macro
	msgbox("Entered in macro")

	RunMacro = CInt(ActiveDocument.Variables("mRunMacro").GetContent.String)
	
	if RunMacro = 1 then
		msgbox("Macro executed")
'YOUR CODE HERE ActiveDocument.Variables("mRunMacro").SetContent 0, false ActiveDocument.Save ActiveDocument.GetApplication.Quit else msgbox("Macro NOT executed") end if end sub

Bassically, if the variable "mRunMacro" is 1, macro is executed. Else, it does nothing. If macro is executed, I set the variable "mRunMacro" to 0 (so I can open the QV by myself without macro execution), I save the QV file (because at least I changed tha variable value so document save is needed) and finally I close the app (because if macro is executed it is launched by a .bat file and I want that the app closes on finish).

Tha last thing you need is to add your own code. It may be something like

ActiveDocument.Fields("Month").Select Month(now)
ActiveDocument.Fields("Year").Select Year(now)

ActiveDocument.PrintReport "[YOUR REPORT ID]"

I attach a QV and file so you can test but you have to create your own bat file following the instrucions above.

For more about macros I refer you to the documentation (QlikView Automation Reference.pdf and APIguide.qvw)

Bests,

Jaime. 

View solution in original post

5 Replies
marcus_malinow
Partner - Specialist III
Partner - Specialist III

The easy way is to use NPrinting

LKSRCH
Contributor II
Contributor II
Author

I know, unfortunately we don't have NPrinting yet.
So I have to find a way by using batch/macros.

jaibau1993
Partner - Creator III
Partner - Creator III

Hi!

I had a similar issue. I solved it as follows:

First, I created a .bat file that opens the QlikView file and passes a variable:

"C:\Program Files\QlikView\QV.exe"  /vmRunMacro=1  "C:\QV\MacroFromCMD.qvw"

that line opens MacroFromCMD.qvw and sets the variable vmRunMacro (that must be created in the QV file) to value 1.

Secondly, I created an action "On Open" (Settings >> Document Properties >> Triggers >> OnOpen >> Edit Actions). It is a "Run Macro" action that runs the following code:

Sub Macro
	msgbox("Entered in macro")

	RunMacro = CInt(ActiveDocument.Variables("mRunMacro").GetContent.String)
	
	if RunMacro = 1 then
		msgbox("Macro executed")
'YOUR CODE HERE ActiveDocument.Variables("mRunMacro").SetContent 0, false ActiveDocument.Save ActiveDocument.GetApplication.Quit else msgbox("Macro NOT executed") end if end sub

Bassically, if the variable "mRunMacro" is 1, macro is executed. Else, it does nothing. If macro is executed, I set the variable "mRunMacro" to 0 (so I can open the QV by myself without macro execution), I save the QV file (because at least I changed tha variable value so document save is needed) and finally I close the app (because if macro is executed it is launched by a .bat file and I want that the app closes on finish).

Tha last thing you need is to add your own code. It may be something like

ActiveDocument.Fields("Month").Select Month(now)
ActiveDocument.Fields("Year").Select Year(now)

ActiveDocument.PrintReport "[YOUR REPORT ID]"

I attach a QV and file so you can test but you have to create your own bat file following the instrucions above.

For more about macros I refer you to the documentation (QlikView Automation Reference.pdf and APIguide.qvw)

Bests,

Jaime. 

LKSRCH
Contributor II
Contributor II
Author

Thank you for your detailed answer! 

I just solved it a bit different using this:

https://community.qlik.com/t5/QlikView-App-Development/Run-a-macro-on-post-reload/m-p/342101/highlig...

and the apiguide. 

I will mark your answer as solution. 

 

 

jaibau1993
Partner - Creator III
Partner - Creator III

Thanks for that reference! 🙂