Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Dear All,
I am trying to automatically save various reports as PDF. I need them to have different file names.
I have a field called ID, and i need to make a loop in that field and save each report in the same folder but with different name.
Customer | ID | Output file name |
---|---|---|
Mickey | 1 | 1-Mickey.pdf |
Pluto | 2 | 2-Pluto.pdf |
Daisy | 3 | 3-Daisy.pdf |
Daisy | 4 | 4-Daisy.pdf |
Donald | 5 | 5-Donald.pdf |
Goofy | 6 | 6-Goofy.pdf |
So, I need a macro to do a loop in the ID field that generates each report for each customer and save them in the same folder with the output file name.
Regards,
Alazne.
SOLVED
Sub Print_PDF
' Designed for early bind, set reference to PDFCreator
Dim pdfjob
Dim sPDFName
Dim sPDFPath
'/// Change the output file name here! ///
set fo = ActiveDocument.Fields("CUUID")
set selo = fo.GetSelectedValues
for i = 0 to selo.Count-1
fo.Select selo.Item(i).text
sPDFName = selo.Item(i).text
sPDFPath = "C:\Users\"
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
If .cStart("/NoProcessingAtStartup", True) = False Then
Exit Sub
End if
.cVisible = True
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
' Print the QlikView Report
ActiveDocument.PrintDocReport "RP05", "PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
ActiveDocument.GetApplication.Sleep 20
' in VBScript use WScript.Sleep(20)
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
ActiveDocument.GetApplication.Sleep 20
' in VBScript use WScript.Sleep(20)
Loop
pdfjob.cClose
Set pdfjob = Nothing
next
End Sub
I have a similar problem and the macros I have found so far in community does not work. QV does not report any problem with the macro but the macro is still asking me to introduce the filename.
SOLVED
Sub Print_PDF
' Designed for early bind, set reference to PDFCreator
Dim pdfjob
Dim sPDFName
Dim sPDFPath
'/// Change the output file name here! ///
set fo = ActiveDocument.Fields("CUUID")
set selo = fo.GetSelectedValues
for i = 0 to selo.Count-1
fo.Select selo.Item(i).text
sPDFName = selo.Item(i).text
sPDFPath = "C:\Users\"
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
If .cStart("/NoProcessingAtStartup", True) = False Then
Exit Sub
End if
.cVisible = True
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
' Print the QlikView Report
ActiveDocument.PrintDocReport "RP05", "PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
ActiveDocument.GetApplication.Sleep 20
' in VBScript use WScript.Sleep(20)
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
ActiveDocument.GetApplication.Sleep 20
' in VBScript use WScript.Sleep(20)
Loop
pdfjob.cClose
Set pdfjob = Nothing
next
End Sub