Saving Publisher files as PDFs in VBA

DougRobertson

Active Member
Joined
Sep 22, 2009
Messages
334
Office Version
  1. 365
Platform
  1. Windows
Greetings!

Years ago I created a macro which converted Publisher files to PDFs and created emails which they would then be attached to. It's worked flawlessly for years.

Then along came the Windows 10 Anniversary Update . . . . or so the timing would suggest, and now most of the PDFs show up with internal boxes for text, but no actual text. When I run the code line by line everything comes out perfectly, but when I run the macro in real time, again the text is missing.

Here's the code I'm using:

Code:
    Dim pubApp As Publisher.Application
    Dim pubDoc As Publisher.Document
    Set pubApp = New Publisher.Application

    pubApp.Open "C:\Folder1\EAGLE'S VIEW.pub"

    pubApp.ActiveDocument.ExportAsFixedFormat pbFixedFormatTypePDF, _
        "C:\Folder2\" & _
            "EAGLE'S VIEW - A.pdf"

Thank you in advance for any and all help!

~ DWR
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Thanks Jim, however that doesn't change the way the macro works. It still opens the first Publisher file, doesn't export it properly (no text), then stays open.

When I step through the code line by line it works properly, but I noticed that the Publisher file doesn't actually open. It does however export the Publisher document to PDF properly - any idea how it can do that if it doesn't actually open?

~ DWR
 
Upvote 0
Okay, after a substantial trial-and-error session, I've discovered that it seems to be a timing issue. By inserting a 1-second pause before the first Open command, it works like a charm again!

As in:


Code:
    Dim pubApp As Publisher.Application
    Dim pubDoc As Publisher.Document
    Set pubApp = New Publisher.Application

    If iFirstTimeThrough <> "NO" Then Application.Wait (Now + TimeValue("0:00:01"))   ' 1 second pause
    iFirstTimeThrough = "NO"

    pubApp.Open "C:\Folder1\EAGLE'S VIEW.pub"

    pubApp.ActiveDocument.ExportAsFixedFormat pbFixedFormatTypePDF, _
        "C:\Folder2\" & _
            "EAGLE'S VIEW - A.pdf"


Thanks for your help Jim,

~ DWR
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top