Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Highlighted
quantran
Contributor

How to Implement Macro and Function

I found the following in a previous post at Is it possible to write a function to print a sheet (not report)? 

I do not know how to implement it.  I am not sure where I put the sub portion and the function portion.  Do I put the sub portion into a button with Action = Run macro?  Where do I put the function?

-------------------------------------------------------------------------------------------------------

sub Export

tempFolder="D:\Upendra\"

reportName="TestDashboard"

reportFile = tempFolder & reportName & day(date) & monthname(month(date))&".pdf"

'msgbox reportFile

printReportPDF reportFile

ActiveDocument.GetApplication.Sleep 5000

ActiveDocument.sheets("SH05").Print

ActiveDocument.GetApplication.Sleep 5000

' SendMail

'msgbox "saved."

end sub

'===========================================================================

Function printReportPDF(pdfOutputFile)

Set WSHShell = CreateObject("WScript.Shell")

WSHShell.RegWrite "HKCU\Software\QlikviewPDF\OutputFile", pdfOutputFile, "REG_SZ"

WSHShell.RegWrite "HKCU\Software\QlikviewPDF\BypassSaveAs", "1", "REG_SZ"

Set WSHShell = nothing

End function

Tags (4)
2 Replies
sudeepkm
Valued Contributor III

Re: How to Implement Macro and Function

Open your QVW and then press CTRL+M. That opens the macro editor and then you can paste the above code.

You need to update the macro code by providing a location that exists in your system.

tempFolder="D:\Upendra\"

and the Sheet ID of the sheet that you want to print.

ActiveDocument.sheets("SH05").Print

Make sure you have "Allow System Access" selected.

t275285_1.png

Create a button and then call the macro.

t275285.png

quantran
Contributor

Re: How to Implement Macro and Function

Thank you. This is great.  I was wondering where do I call the function?