PDA

View Full Version : [SOLVED:] User type not defined error trying to merge pdfs



branston
10-10-2019, 01:26 PM
Hi

I am hoping someone can help me out here.

I am using some code (by the great Kenneth Hobs) and have pdf creator installed but getting 'user type not defined' error. I have played around with it for hours to no avail.

All I am trying to do is merge some pdf files into one pdf file. I have pdfcreator v2.5.3 installed and have checked the reference libraries for pdfcreator. The pdf files are in the same location as my excel file.

(I did try the same thing previously with adobe acrobat 6 installed and checked the relevant references but had the same problem hence going down the pdfcreator route.) I am wondering if there is something obvious I am missing. Can anyone help? TIA


This line is where the error is.Dim oPDF As PDFCreator.PdfCreatorObj, q As PDFCreator.Queue



I have the references added to the PDFCreator_COM and PDFCreatorApp 1.0 Type Library


Sub Test_PDFCreatorCombine()
Dim fn(0 To 1) As String, s As String
fn(0) = ThisWorkbook.Path & "\1.pdf"
fn(1) = ThisWorkbook.Path & "\2.pdf"
s = ThisWorkbook.Path & "\PDFCreatorCombined.pdf"

PDFCreatorCombine fn(), s

If vbYes = MsgBox(s, vbYesNo + vbQuestion, "Open?") Then Shell ("cmd /c " & """" & s & """")
End Sub

' Macro Purpose: Print to PDF file using PDFCreator v2.3.2, Kenneth Hobson, Oct. 8, 2016
' (Download from http://sourceforge.net/projects/pdfcreator/)
' COM interface, http://www.pdfforge.org/pdfcreator/manual/com-interface
' Designed for early bind, set reference to: PDFCreator - Your OpenSource PDF Solution
' sPDFName() assumed to be 0 index based string array.
Sub PDFCreatorCombine(sPDFName() As String, sMergedPDFname As String, _
Optional tfKillMergedFile As Boolean = True)
Dim oPDF As PDFCreator.PdfCreatorObj, q As PDFCreator.Queue
Dim pj As PrintJob
Dim i As Integer, ii As Integer
Dim fso As Object, tf As Boolean
Dim s() As String

On Error GoTo EndSub
Set fso = CreateObject("Scripting.FileSystemObject")
If tfKillMergedFile And fso.FileExists(sMergedPDFname) Then Kill sMergedPDFname

For i = 0 To UBound(sPDFName)
If fso.FileExists(sPDFName(i)) Then
ii = ii + 1
ReDim Preserve s(1 To ii)
s(ii) = sPDFName(i)
End If
Next i

Set q = New PDFCreator.Queue
With q
.Initialize

Set oPDF = New PDFCreator.PdfCreatorObj 'PDFCreator.clsPDFCreator
tf = .WaitForJobs(ii, 5) 'Wait 5 seconds for jobs to que

For i = 1 To UBound(s)
oPDF.AddFileToQueue s(i)
Next i
.MergeAllJobs

Set pj = q.NextJob
With pj
.SetProfileByGuid "DefaultGuid"
.SetProfileSetting "Printing.PrinterName", "PDFCreator"
.SetProfileSetting "Printing.SelectPrinter", "SelectedPrinter"
.SetProfileSetting "OpenViewer", "false"
.SetProfileSetting "OpenWithPdfArchitect", "false"
.SetProfileSetting "ShowProgress", "false"
.ConvertTo sMergedPDFname
End With
End With
EndSub:
If Not q Is Nothing Then q.ReleaseCom
End Sub
Thank you