I use VBA code to create and save pdf file however I receive error :"user type not defined "
The highlighted line like the following;
Dim pdfjob As PDFCreator.clsPDFCreator
PDF creator is already set as a reference. The code works on another computer with Excel 2003, however not working on my computer (excel 2013).
Any help is appreciated!
The highlighted line like the following;
Dim pdfjob As PDFCreator.clsPDFCreator
PDF creator is already set as a reference. The code works on another computer with Excel 2003, however not working on my computer (excel 2013).
Any help is appreciated!
Code:
Sub PrintToPDF_Early()
'Author : Ken Puls ([URL="http://www.excelguru.ca"]Excelguru Help Site - Welcome[/URL])
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from [URL="http://sourceforge.net/projects/pdfcreator/"]PDFCreator | SourceForge.net[/URL])
' Designed for early bind, set reference to PDFCreator
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
'/// Change the output file name here! ///
If UserForm1.TextBox4.Text <> "" Then
sPDFName = "AKSAN" & "_" & UserForm1.TextBox4.Text & "_" & UserForm1.TextBox7.Text & "_" & UserForm1.TextBox5.Text & "_" & UserForm1.tarih11.Text & ".pdf"
Else
sPDFName = "AKSAN" & "_" & UserForm1.ComboBox6.Text & "_" & UserForm1.TextBox7.Text & "_" & UserForm1.TextBox5.Text & "_" & UserForm1.TextBox5.Text & "_" & UserForm1.tarih11.Text & ".pdf"
nlef = Left(sPDFName, 4)
nrig = Left(sPDFName, 4)
End If
sPDFPath1 = ActiveWorkbook.Path & "\giden\"
sPDFPath = ActiveWorkbook.Path & "\bugun\" '"C:\Documents and Settings\ksy05\Desktop\ramo\bugun\"
'/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
'/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
Sheets("form").PrintOut copies:=1, ActivePrinter:="PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
End Sub
Last edited by a moderator: