

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Modify PDF-XChange settings from VBA code
Hi,
I'm trying to create a daily pdf report from my Qlikview project.
I built a new report schema thanks to the Editor and I named it 'RP01'.
After, I wrote the following VBA code to create pdf, setting saving path and no visualization of 'Save as...' window.
sub printRP01
printReportPDF "Report_giornaliero.pdf"
ActiveDocument.GetApplication.Sleep 2000
ActiveDocument.PrintReport "RP01", "PDF-XChange 3.0",False
ActiveDocument.GetApplication.Sleep 10000
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
Unfortunately, this code create the pdf file, but named QlikView Printing.pdf and saves it into the default path.
Someone could you suggest me how modify the VB code to set up these parameters?
Thanks
Accepted Solutions


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe it's just missing the print-statement itself. If not you might use one of my examples which is usually executed in a loop and look like:
public Sub Print_PDF(sPDFPath_src, outputFile, sReportID, doc)
'msgbox sPDFPath_src & " - " & outputFile & " - " & sReportID
dim objFSO
set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(sPDFPath_src) then 'If the file exists then -> delete
objFSO.DeleteFile sPDFPath_src
End If
doc.PrintReport sReportID, "PDF-XChange 3.0", false
doc.GetApplication.Sleep 2500
objFSO.MoveFile sPDFPath_src, outputFile
Set objFSO = Nothing
End Sub
Before enabling the print and move action just use the msgbox to check that paths and filenames and so on are defined properly.
- Marcus


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your code mixed two different pdf-printer and therefore it couldn't work. Further I don't know if and how the target-path from PDF-XChange could be adjusted but there is a workaround which prints everything with the same name to the same path and moving and renaming it afterwards. The howto for it could you find here: generate-pdf-with-Xchange.
- Marcus


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Marcus for reply.
I tried to change my VB code following the post you linked.
Now, my new code is:
Sub Print_PDF
ActiveDocument.PrintReport "RP01", "PDF-XChange 3.0", false
Set objFSO = CreateObject("Scripting.FileSystemObject")
''If the folder not exists then -> create
if Not objFSO.FolderExists("C:\Users\ext_onit_dwh\Documents") Then
Set newfolder = objFSO.CreateFolder("C:\Users\ext_onit_dwh\Documents")
End If
PDFFullName = "C:\Users\ext_onit_dwh\Documents\Report_giornaliero.pdf"
'If the file exists then -> delete
If objFSO.FileExists(PDFFullName) then
objFSO.DeleteFile PDFFullName
End If
objFSO.MoveFile "C:\Users\ext_onit_dwh\Documents", PDFFullName
Set objFSO = Nothing
ActiveDocument.GetApplication.Sleep 2000
End Sub
But it doesn't work.
Do you explain me if you find something wrong into the code below?
Thank you.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe it's just missing the print-statement itself. If not you might use one of my examples which is usually executed in a loop and look like:
public Sub Print_PDF(sPDFPath_src, outputFile, sReportID, doc)
'msgbox sPDFPath_src & " - " & outputFile & " - " & sReportID
dim objFSO
set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(sPDFPath_src) then 'If the file exists then -> delete
objFSO.DeleteFile sPDFPath_src
End If
doc.PrintReport sReportID, "PDF-XChange 3.0", false
doc.GetApplication.Sleep 2500
objFSO.MoveFile sPDFPath_src, outputFile
Set objFSO = Nothing
End Sub
Before enabling the print and move action just use the msgbox to check that paths and filenames and so on are defined properly.
- Marcus


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works!!!
I wrong wrote the sPDFPath_src, now I change the specification of this variable and I obtained the right result.
My final code is:
public Sub Print_PDF()
sPDFPath_src="C:\Users\ext_onit_dwh\Documents\QlikView Printing.pdf"
outputFile = "C:\Users\ext_onit_dwh\Documents\Report_giornaliero.pdf"
sReportID = "RP01"
'msgbox sPDFPath_src & " - " & outputFile & " - " & sReportID
dim objFSO
set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(sPDFPath_src) then 'If the file exists then -> delete
objFSO.DeleteFile sPDFPath_src
End If
ActiveDocument.PrintReport sReportID, "PDF-XChange 3.0", false
ActiveDocument.GetApplication.Sleep 2500
'msgbox "Muovo in altro nome"
objFSO.MoveFile sPDFPath_src, outputFile
Set objFSO = Nothing
'SendGMail
End Sub
Thank you very much Marcus
