How to Export Every Visio Page as a Separate PDF Automatically via VBA
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.

- 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 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 /, \, *, ?, <, >, |).
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.
In Microsoft Visio, press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) Editor.
In the VBA Editor, click on 'Insert' in the top menu bar, and then select 'Module' to create a blank workspace for your script.
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
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.

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. Download and Install: Visit the official WPS website to download the free WPS Office installer and run it on your device.
- 2. Open Your Documents: Launch WPS Office and easily open your existing Microsoft Office files (.docx, .xlsx, .pptx) with full format compatibility.
- 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.

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.




