Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
Very new to this forum and I was trying to code some macro to create and save report in PDF format. I found some code in this forum and its seems to working, but not as I expected. The problem in the below code is it prompts window to save as and then need to press OK to save the repot. But I wanted not to do this. I installed CutePDF writer.
Any suggesion will be appricated and thantks in advance.
Sub PrintReport
Set WSHShell = CreateObject("WScript.Shell")
fln = "C:\myreport.pdf"
RegKey = "HKEY_CURRENT_USER\Software\CutePDF"
WSHShell.RegWrite RegKey & "BypassSaveAs", 1
WSHShell.RegWrite RegKey & "OutputFile", fln,len(fln)
ActiveDocument.GetApplication.Sleep 2000
ActiveDocument.PrintDocReport "RP01", "CutePDF Writer"
ActiveDocument.GetApplication.Sleep 2000
WSHShell.RegWrite RegKey & "BypassSaveAs", 0
WSHShell.RegWrite RegKey & "OutputFile", ""
Set WSHShell = nothing
End Sub
Am not sure, whether your script works for the CutePDF. Am using the basically the same code (it has been posted earlier in this forum), but for the QlikView PDF-printer (you may download it from the QV-page):
Sub PrintReport
fPrintReport2PDF "RP04", "c:\temp\test.pdf" ' CALLS FUNCTION
End Sub
Function fPrintReport2PDF(oReport, pdfOutputFile)
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", pdfOutputFile, "REG_SZ"
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "1", "REG_SZ"
ActiveDocument.PrintReport oReport, "QlikViewPDF", false
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "0", "REG_SZ"
set WSHShell = nothing
End Function
HTH
Peter
Thanks for the reply, I tried to get the QlikviewPDF download and were not found the link... I will try to look on this ...
You should be able to use the CutePDF writer with that macro if you just change the registry key values from ...\QlikViewPDF\.. to ..\CutePDF\...
your change the highlighted line should solve your problem:
Sub PrintReport
Set WSHShell = CreateObject("WScript.Shell")
fln = "C:\myreport.pdf"
RegKey = "HKEY_CURRENT_USER\Software\CutePDF\"
WSHShell.RegWrite RegKey & "BypassSaveAs", 1
WSHShell.RegWrite RegKey & "OutputFile", fln,len(fln)
ActiveDocument.GetApplication.Sleep 2000
ActiveDocument.GetApplication.Sleep 2000
WSHShell.RegWrite RegKey & "BypassSaveAs", 0
WSHShell.RegWrite RegKey & "OutputFile", ""
Set WSHShell = nothing
End Sub
I tried the macro suggested by Peter to save the Report to PDF. However, instead of saving the report as a PDF to the specified folder, it just prints the report directly to the printer. I would like to just save the PDF report to a folder without printing it. Below is the macro.
Sub PrintReport
fPrintReport2PDF "RP01", "C:\file.pdf" ' CALLS FUNCTION
End Sub
Function fPrintReport2PDF(oReport, pdfOutputFile)
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", pdfOutputFile, "REG_SZ"
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "1", "REG_SZ"
ActiveDocument.PrintReport oReport, "QlikViewPDF", false
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "0", "REG_SZ"
set WSHShell = nothing
End Function
See code below that I used, it work without any issues...
sub PrintReport
'Set The user selection
set v = ActiveDocument.Variables("vOSUSER")
mUser = v.GetContent.String
ActiveDocument.Fields("JiraUser").Select(mUser)
Set WSHShell = CreateObject("WScript.Shell")
fln = "C:\myreport.pdf"
RegKey = "HKEY_CURRENT_USER\Software\QlikViewPDF\"
WSHShell.RegWrite RegKey & "BypassSaveAs", 1
WSHShell.RegWrite RegKey & "OutputFile", fln
ActiveDocument.GetApplication.Sleep 2000
ActiveDocument.PrintDocReport "RP01", "QlikViewPDF"
ActiveDocument.GetApplication.Sleep 2000
WSHShell.RegWrite RegKey & "BypassSaveAs", 0
WSHShell.RegWrite RegKey & "OutputFile", ""
Set WSHShell = nothing
end sub
What does your vOSUSER variable contain ? Is that just the OSUser function ? How about the JiraUser ? I don't have such a field in my app.
Hi - vOSUSER to get the user prfile and filter based on user name. You can forget the first 3 lines.