0
votes

I am trying to write a macro that creates a pdf of a Word document.

The code I have been using to do this uses ActiveDocument.ExportAsFixedFormat. This works up to a point, but it tends to fail when creating a pdf of a large document (and some of the documents I'll be processing with this macro run to thousands of pages).

My understanding is that the ExportAsFixedFormat method uses Word's built-in PDF creation methods. What I really want to do is use Adobe Acrobat to do the PDF conversion. If I do that manually by clicking on the export as pdf buttons within Word (I have Adobe Acrobat installed on my machine) then everything is fine. It uses the actual Adobe Acrobat PDF conversion, and my PDF gets created without errors even on documents large enough to cause the ExportAsFixedFormat method to fail.

I've been trying to figure out how to automate the conversion to PDF from VBA using Acrobat, and banging my head against a brick wall.

I discovered the CreatePDFEx method, which in theory looks like it should do what I want, but I also discovered warnings that this is not a supported method and is not recommended. See here:

https://forums.adobe.com/thread/286431

And indeed when I tried it, it didn't work.

I then discovered the AcroExch.AVDoc and AcroExch.PDDoc objects, which looked like it might be another way. See, for example, here:

https://forums.adobe.com/thread/301714

That also came with a warning that it wasn't supported. When I tried it, it worked, but it was painfully slow, even with documents of just a few pages. I hate to think what it would be like with a 5000 page document.

Is it actually possible to do this? It doesn't seem like it should be rocket science, but I am failing to find anything that works.

All I want to be able to do is to reliably create pdfs from large Word docs. I think that probably the way to do that is to figure out how to use Adobe's tools via VBA (is there a supported method?), but I'd be perfectly happy with the built in Word method if I could solve the problem of it failing with large documents.

Many thanks for any help.

Edit: I should also have mentioned that I need my Word headings to end up as PDF bookmarks. The ExportAsFixedFormat method does that, but some other methods don't.

2

2 Answers

0
votes

You can use the SaveAs or SaveAs2 method to save as a PDF instead of ExportAsFixedFormat. For example:

ActiveDocument.SaveAs FileName:="Filename.pdf", FileFormat:=wdFormatPDF

0
votes

On a bit more playing around, I did come up with one method which is an official supported method and uses the Adobe PDF creator:

ActivePrinter = "Adobe PDF"
ActiveDocument.PrintOut

The problem with that is that it doesn't turn my Word headings into PDF bookmarks.

Does anyone know if it's possible to set some options in that code so that it does?