logo
search
VBA & Macro Problems

How to Export Every Visio Page as a Separate PDF Automatically via VBA

Bushra ParveenBushra Parveen Sep 27, 2026 869 views

Question details

The user needs to automatically export each foreground page of a Visio document into a separate PDF file, using the page name as the filename.

How to Export Every Visio Page as a Separate PDF Automatically
Product
Microsoft Visio
Device & OS
not provided
Scenario
Automating the batch export of multi-page Visio documents into individual PDF files to avoid manually saving each page.
Observed behavior
By default, Visio exports the entire document as a single PDF. A VBA macro is required to loop through the document and save each page individually.
Before you start

Before running the macro, ensure your Visio document is saved locally so the file path is recognized, and verify that all page names contain only valid Windows filename characters (avoiding symbols like /, \, *, ?, <, >, |).

Solution 1Recommended

Use a VBA Macro to Export Pages as Separate PDFs

Implement a VBA script that loops through all pages in the active Visio document, skips background pages, and exports each foreground page as a distinct PDF file in the same directory.

This macro utilizes the ExportAsFixedFormat method to handle the PDF conversion. It checks the 'Background' property of each page to ensure that only your actual diagram pages are processed.

1
Open the VBA Editor

In Microsoft Visio, press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) Editor.

2
Insert a New Module

In the VBA Editor, click on 'Insert' in the top menu bar, and then select 'Module' to create a blank workspace for your script.

3
Paste the Macro Code

Copy and paste the following code into the module window: Sub SaveEachPageAsPDF() Dim pg As Visio.Page Dim sPDFFullName As String For Each pg In ActiveDocument.Pages If Not pg.Background Then sPDFFullName = Application.ActiveDocument.Path & pg.Name & ".pdf" Application.ActiveDocument.ExportAsFixedFormat _ Visio.visFixedFormatPDF, sPDFFullName, _ Visio.visDocExIntentPrint, _ Visio.visPrintFromTo, pg.Index, pg.Index End If Next pg End Sub

4
Run the Macro

Click anywhere inside the pasted code and press 'F5', or click 'Run' > 'Run Sub/UserForm' from the top menu. The script will automatically generate the PDFs in the same folder as your Visio document.

Use a VBA Macro to Export Pages as Separate PDFs
Macro Execution Successful: Once the macro completes, check the folder where your Visio file is stored. You will find a separate PDF file for each foreground page, named according to the Visio page tab.
Free Microsoft Office alternative

Looking for a More Streamlined Office Suite?

While Microsoft Visio requires custom VBA macros to handle specific export tasks, WPS Office offers a free, lightweight, and user-friendly alternative for your primary document and PDF needs. WPS Office includes an advanced built-in PDF toolkit that makes exporting and splitting documents effortless.

  1. 1. Download and Install: Visit the official WPS website to download the free WPS Office installer and run it on your device.
  2. 2. Open Your Documents: Launch WPS Office and easily open your existing Microsoft Office files (.docx, .xlsx, .pptx) with full format compatibility.
  3. 3. Use Built-in PDF Tools: Navigate to the 'Tools' or 'PDF' tab to access powerful, intuitive features for exporting, splitting, and converting files to PDF without coding.
Free, lightweight, and highly compatible with Microsoft Office formats (Word, Excel, PowerPoint)Built-in, robust PDF editing and conversion tools that eliminate the need for complex macrosSeamless migration with a familiar user interface for immediate productivityIntegrated flowchart and diagramming tools suitable for most standard business processes
QA img-9

Frequently Asked Questions

Why does the macro fail with a path error?

This happens if your Visio document has not been saved yet. The code relies on 'Application.ActiveDocument.Path', which returns an empty string for unsaved files. Save your file to a local folder first.

Can I save the exported PDFs to a specific folder instead?

Yes, you can modify the 'sPDFFullName' variable in the VBA script. Replace 'Application.ActiveDocument.Path & pg.Name & ".pdf"' with a static path like '"C:\Your\Custom\Folder\" & pg.Name & ".pdf"'.

Will this macro also export my background pages?

No. The macro specifically includes an 'If Not pg.Background Then' condition, which instructs Visio to skip background pages and only export the actual foreground diagram pages.

What if my page name contains invalid characters?

Windows does not allow certain characters (like /, \, *, ?, <, >) in filenames. If a Visio page name contains any of these, the macro will crash. Rename your pages to use standard alphanumeric characters before running the script.