PDA

View Full Version : PDF Creator Help



chris9104
10-14-2011, 01:03 AM
I have been using the below code to use pdf creator to save pdfs from word, however, the line highlighted in red keeps resetting all the word fields to the default, just before it prints. Also since updating to the latest version, it printing with the default file name, rather than what I have set it to. Please can someone help?



Sub CmdSave()
Call ErrHandler

Dim Var1 As String
Var1 = ActiveDocument.Bookmarks("Reference").Range.Text
If Var1 = "00000" Then
MsgBox "Please enter an account number."
ActiveDocument.FormFields(6).Select
Exit Sub
End If
Application.DisplayAlerts = False

ActiveDocument.Unprotect
1 Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String
Dim sPrinter As String
Dim lPrintOrder As Long
Dim lDocs As Long
Dim bRestart As Boolean
Dim bBkgrndPrnt As Boolean
Dim mytime As Long

'Activate error handling, capture properties and set req'd settings
With Application
sPrinter = CStr(.ActivePrinter)
.ActivePrinter = "PDFCreator"
bBkgrndPrnt = .Options.PrintBackground
.Options.PrintBackground = False
.ScreenUpdating = False
End With
'/// Change the output file name here! ///
sPDFName = ActiveDocument.Bookmarks("Reference").Range.Text & "-" & ActiveDocument.Bookmarks("Name").Range.Text
sPDFPath = "C:\Documents and Settings\Owner\Desktop\Bills\"
'Check if PDFCreator is already running and attempt to kill the process if so
Do
bRestart = False
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
'PDF Creator is already running. Kill the existing process
Shell "taskkill /f /im PDFCreator.exe", vbHide
DoEvents
Set pdfjob = Nothing
bRestart = True
End If
Loop Until bRestart = False
'Assign settings for PDF job
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print documents to print queue in reverse order

'For lPrintOrder = Application.Documents.Count To 1 Step -1
' Application.Documents(lPrintOrder).PrintOut copies:=1
' lDocs = lDocs + 1
'Next lPrintOrder
Application.ActiveDocument.PrintOut copies:=1
'Wait until all print jobs have entered the print queue
Do Until pdfjob.cCountOfPrintjobs = lDocs
DoEvents
Loop
'Combine all PDFs into a single file and stop the printer
With pdfjob
.cCombineAll
.cPrinterStop = False
End With
'Wait until the file shows up before closing PDF Creator
mytime = 1
Do While mytime < 300
mytime = mytime + 1
Loop

MsgBox "Document has been saved to the Bills file", vbInformation, sPDFName
Cleanup:
'Release objects and terminate PDFCreator
pdfjob.cClose
Set pdfjob = Nothing

'Reset all application settings to user's original settings
With Application
.ScreenUpdating = True
.ActivePrinter = sPrinter
.Options.PrintBackground = False
End With
Application.ActivePrinter = "Brother MFC-7420 USB Printer"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.FormFields(1).Select
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
Application.DisplayAlerts = True

Exit Sub

End Sub

steve_flash
10-20-2011, 08:23 AM
hopefully stupid question.
You have Word 2k7 at least SP2, right?

chris9104
10-20-2011, 02:21 PM
hopefully stupid question.
You have Word 2k7 at least SP2, right?

The comp this is running on only has word 2003.