PrintOut to PDF, but PDF corrupt

I am trying to create a macro that will print various pages of a Word document as a PDF in a specific directory.  Below code seems to work, but when i try to open the PDF, i get the following message:  "Acrobat could not open '2013.pdf' because it is either not supported file type or because the file has been damaged".  I have Adobe XI Pro installed.   I am able to manually print to a PDF without issue.

    ActivePrinter = "Adobe PDF"
    
    Application.PrintOut _
        Background:=True, _
        OutputFileName:="X:\2013.pdf", _
        PrintToFile:=True, _
        Range:=wdPrintRangeOfPages, _
        Item:=wdPrintDocumentWithMarkup, _
        Copies:=1, _
        Pages:="3-7,15", _
        PageType:=wdPrintAllPages, _
        Collate:=True, _
        PrintZoomColumn:=0, _
        PrintZoomRow:=0, _
        PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0

   
   'restore printer to previous default
   Application.ActivePrinter = strCurrentPrinter



Mike
The file is not corrupt - specifying a name and printing to file sets the file type as postscript and not PDF.

Try the following instead. It should save the file as a document in the location then create the PDF.

Dim Printer As String
ActiveDocument.SaveAs "X:\2013.docx"
    With Dialogs(wdDialogFilePrintSetup)
        Printer = .Printer
        .Printer = "Adobe PDF"
        .Execute
    End With
    Application.PrintOut PrintToFile:=False, _
        Range:=wdPrintRangeOfPages, _
        Item:=wdPrintDocumentWithMarkup, _
        Copies:=1, _
        Pages:="3-7,15", _
        PageType:=wdPrintAllPages
    With Dialogs(wdDialogFilePrintSetup)
        .Printer = Printer
        .Execute
    End With
Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

can this be accomplished without dialog boxes?  i want it to be "hands off" to the users.  


..

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

You can, but it gets a whole lot more complicated if merely setting an output folder in the driver properties is unacceptable. The macro at the end of the thread at http://www.mrexcel.com/forum/excel-questions/312792-visual-basic-applications-controlling-acrobat-distiller.html should give you a clue.


Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

i was trying to create something to avoid spending a few thousand for PlantPress.  I'll give that thread a try.  thanks!

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
 "C:\Report.doc", ExportFormat:=wdExportFormatPDF, _
 OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
 wdExportFromTo, From:=1, To:=3, Item:=wdExportDocumentContent, _
 IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
 wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
 True, UseISO19005_1:=False

 

 

This worked better yet.  No need to mess with postscript and distiller.  Simply creates the PDF.

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

It does work, but it does not use Acrobat which I assumed from your original post was what you required. The built-in Word converter has a number of limitations when compared with the output from Acrobat, but if it works for you then fine.
Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 30, 2025 Views 3,390 Applies to: