andrewvanmar
11-21-2007, 04:28 AM
I use the below script generously created by Ken Pulse but i'm encountering a problem with the PDF creator;
I.T. wants us to use that same pdfcreator, though installed on the network, and not locally.
Since this document will be used on several different networks (all with the PDF creator installed) I would like to be able to do the following:
have the script check for a locally installed pdfcreator ( should be in the ref. library then), and if it doesn't find one, pop up a choose printer dialogue.
Is this possible? (and if so, then how?)
Thanks! :thumb
Private Sub CommandButton1_Click()
'Author : Ken Puls (www.excelguru.ca (http://www.excelguru.ca))
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/)
' Designed for early bind, set reference to PDFCreator
'
'Adapted by Charlize for printing certain worksheets (15/06/2007)
Application.ScreenUpdating = False
'this checks if a bunch of required fields are filled in
If IsComplete = False Then
MsgBox "Cannot PDF, please fill in all the fields in the orderform. Required fields are colored yellow. Please check all sheets for missing information."
Exit Sub
End If
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim lSheet As Long
Dim lTtlSheets As Long
Dim mpFilename As Variant
If Not ActiveWorkbook.Saved Then
mpFilename = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")
If mpFilename = False Then
Exit Sub
Else
ActiveWorkbook.SaveAs mpFilename
'go on with the routine
End If
End If
'/// Change the output file name here! ///
sPDFName = ActiveWorkbook.Name
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
Set pdfjob = New PDFCreator.clsPDFCreator
'Make sure the PDF printer can start
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "Error!"
Exit Sub
End If
'Set all defaults
With pdfjob
.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
lTtlSheets = Application.Sheets.Count
For lSheet = 1 To Application.Sheets.Count
On Error Resume Next 'To deal with chart sheets
If Sheets(lSheet).Name = "Information" Or _
Sheets(lSheet).Name = "Service Details" Or _
Sheets(lSheet).Name = "Signatures and pricing" Then
If Not IsEmpty(Application.Sheets(lSheet).UsedRange) Then
Application.Sheets(lSheet).PrintOut copies:=1, ActivePrinter:="PDFCreator"
Application.Wait (Now + TimeValue("0:00:02"))
Else
lTtlSheets = lTtlSheets - 1
End If
Else
lTtlSheets = lTtlSheets - 1
End If
On Error GoTo 0
Next lSheet
'Wait until all print jobs have entered the print queue
Do Until pdfjob.cCountOfPrintjobs = lTtlSheets
DoEvents
Loop
'Combine all PDFs into a single file and stop the printer
With pdfjob
.cCombineAll
.cPrinterStop = False
End With
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:02"))
pdfjob.cClose
Set pdfjob = Nothing
MsgBox "PDF File successfully created. The folder containing the PDF will now be opened. Click OK to proceed.", vbInformation, "PDF creation ..."
Call ShowPDF
Application.ScreenUpdating = True
End Sub
I.T. wants us to use that same pdfcreator, though installed on the network, and not locally.
Since this document will be used on several different networks (all with the PDF creator installed) I would like to be able to do the following:
have the script check for a locally installed pdfcreator ( should be in the ref. library then), and if it doesn't find one, pop up a choose printer dialogue.
Is this possible? (and if so, then how?)
Thanks! :thumb
Private Sub CommandButton1_Click()
'Author : Ken Puls (www.excelguru.ca (http://www.excelguru.ca))
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/)
' Designed for early bind, set reference to PDFCreator
'
'Adapted by Charlize for printing certain worksheets (15/06/2007)
Application.ScreenUpdating = False
'this checks if a bunch of required fields are filled in
If IsComplete = False Then
MsgBox "Cannot PDF, please fill in all the fields in the orderform. Required fields are colored yellow. Please check all sheets for missing information."
Exit Sub
End If
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim lSheet As Long
Dim lTtlSheets As Long
Dim mpFilename As Variant
If Not ActiveWorkbook.Saved Then
mpFilename = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")
If mpFilename = False Then
Exit Sub
Else
ActiveWorkbook.SaveAs mpFilename
'go on with the routine
End If
End If
'/// Change the output file name here! ///
sPDFName = ActiveWorkbook.Name
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
Set pdfjob = New PDFCreator.clsPDFCreator
'Make sure the PDF printer can start
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "Error!"
Exit Sub
End If
'Set all defaults
With pdfjob
.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
lTtlSheets = Application.Sheets.Count
For lSheet = 1 To Application.Sheets.Count
On Error Resume Next 'To deal with chart sheets
If Sheets(lSheet).Name = "Information" Or _
Sheets(lSheet).Name = "Service Details" Or _
Sheets(lSheet).Name = "Signatures and pricing" Then
If Not IsEmpty(Application.Sheets(lSheet).UsedRange) Then
Application.Sheets(lSheet).PrintOut copies:=1, ActivePrinter:="PDFCreator"
Application.Wait (Now + TimeValue("0:00:02"))
Else
lTtlSheets = lTtlSheets - 1
End If
Else
lTtlSheets = lTtlSheets - 1
End If
On Error GoTo 0
Next lSheet
'Wait until all print jobs have entered the print queue
Do Until pdfjob.cCountOfPrintjobs = lTtlSheets
DoEvents
Loop
'Combine all PDFs into a single file and stop the printer
With pdfjob
.cCombineAll
.cPrinterStop = False
End With
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:02"))
pdfjob.cClose
Set pdfjob = Nothing
MsgBox "PDF File successfully created. The folder containing the PDF will now be opened. Click OK to proceed.", vbInformation, "PDF creation ..."
Call ShowPDF
Application.ScreenUpdating = True
End Sub