Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

2 Replies
sudeepkm
Specialist III
Specialist III

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

Anonymous
Not applicable
Author

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