How-to: Bulk-export Microsoft Publisher documents to PDF.

Microsoft Publisher will be deprecated from October 2026.

The macro below can be used to bulk convert/export all the publisher (.pub) documents in a folder and its sub-folders.

Private Sub exportPDF(ByVal SourceFolderName As String)
' Open a folder and scan for .pub files

' Required references (Tools > References):
'   Microsoft Scripting Run-time.
'   Microsoft Publisher

Dim appPub As New Publisher.Application
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Dim strBasename As String
Dim strParentname As String
Dim strFileExt As String
Dim objSubfolder As Object

'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder
Set objFolder = objFSO.GetFolder(SourceFolderName)

 'Loop through each file in the folder
For Each objFile In objFolder.Files
    strFileExt = objFSO.GetExtensionName(objFile)
    If strFileExt = "pub" Then
        strBasename = objFSO.GetBaseName(objFile)
        strParentname = objFSO.GetParentFolderName(objFile)
        appPub.Open FileName:=objFile, _
                               ReadOnly:=False, addtorecentfiles:=False, _
                               savechanges:=pbPromptToSaveChanges
        appPub.ActiveWindow.Visible = False
        appPub.ActiveDocument.ExportAsFixedFormat pbFixedFormatTypePDF, strParentname & "\" & strBasename & ".pdf"
        DoEvents
        appPub.ActiveDocument.Close
        appPub.Quit
        Set appPub = Nothing
    End If
Next objFile

'Now repeat for sub-folders
For Each objSubfolder In objFolder.SubFolders
    Call exportPDF(objSubfolder.Path)
Next objSubfolder

End Sub

A zip file containing the above macro in both Microsoft Excel and Microsoft Access forms. You may need to unblock and enable macros.

"It was the labor movement that helped secure so much of what we take for granted today. The 40-hour work week, the minimum wage, family leave, health insurance, Social Security, Medicare, retirement plans. The cornerstones of the middle-class security all bear the union label” ~ Barack Obama


 
Copyright © 1999-2024 SS64.com
Some rights reserved