![]() |
#2
|
||||
|
||||
![]()
Word 2003 does not have the ability to save to PDF. That was introduced with Word 2007.
If you want to batch save as PDF with Word 2003, you will need a third party PDF tool to create the PDFs, that can be supplied with a filename from code. That cuts the choices somewhat. One that does work is PDFCreator, though it comes with a lot of unwanted baggage, so install only the PDFCreator part. I would also recommend installing version 1.7.3 rather than the newer version 2.0 which has even more bloat. Even that version can sometimes be a bit flaky when called from VBA. You will then need a function to create the PDF from your macro. The following has not been tested with Word 2003, but should work Code:
Sub PrintToPDFCreator(sPDFName As String, _ sPDFPath As String, _ oDoc As Document, _ Optional sMasterPass As String, _ Optional sUserPass As String, _ Optional bNoCopy As Boolean, _ Optional bNoPrint As Boolean, _ Optional bNoEdit As Boolean) Dim pdfjob As Object Dim sPrinter As String Dim iCopy As Integer, iPrint As Integer, iEdit As Integer If bNoCopy Then iCopy = 1 Else iCopy = 0 If bNoPrint Then iPrint = 1 Else iPrint = 0 If bNoEdit Then iEdit = 1 Else iEdit = 0 'Change active printer to PDFCreator With Dialogs(wdDialogFilePrintSetup) sPrinter = .Printer .Printer = "PDFCreator" .DoNotSetAsSysDefault = True .Execute End With Set pdfjob = CreateObject("PDFCreator.clsPDFCreator") With pdfjob If .cStart("/NoProcessingAtStartup") = False Then GoTo err_Handler End If .cStart "/NoProcessingAtStartup" .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveDirectory") = sPDFPath .cOption("AutosaveFilename") = sPDFName .cOption("AutosaveFormat") = 0 ' 0 = PDF If Not sMasterPass = vbNullString Then 'The following are required to set security of any kind .cOption("PDFUseSecurity") = 1 .cOption("PDFOwnerPass") = 1 .cOption("PDFOwnerPasswordString") = sMasterPass 'To set individual security options .cOption("PDFDisallowCopy") = iCopy .cOption("PDFDisallowModifyContents") = iEdit .cOption("PDFDisallowPrinting") = iPrint 'To force a user to enter a password before opening .cOption("PDFUserPass") = 1 .cOption("PDFUserPasswordString") = sUserPass 'To change to High encryption .cOption("PDFHighEncryption") = 1 End If .cClearCache End With 'Print the document to PDF oDoc.PrintOut '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 'Restore the original printer With Dialogs(wdDialogFilePrintSetup) .Printer = sPrinter .Execute End With lbl_Exit: Set pdfjob = Nothing Exit Sub err_Handler: MsgBox "Unable to initialize PDFCreator." & vbCr & vbCr & _ "This may be an indication that the PDF application has become corrupted, " & _ "or its spooler blocked by AV software." & vbCr & vbCr & _ "Re-installing PDF Creator may restore normal working." GoTo lbl_Exit End Sub Code:
ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, ExportFormat:=wdExportFormatPDF Code:
PrintToPDFCreator strDocName, tFolder, ActiveDocument
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
cc9083 | Word VBA | 2 | 02-23-2015 01:22 AM |
HTML Links do not work in MS Word 2003 | mswny | Word | 20 | 10-11-2014 02:25 PM |
![]() |
sqlcool | Word | 1 | 04-06-2012 03:06 AM |
![]() |
jonrpullen | Word | 1 | 03-25-2011 02:39 PM |
Word 2003 macro to Word 2007 to 2010 to... | maruapo | Word VBA | 0 | 06-04-2010 03:43 PM |