VBA & Macro Problems

How to Automate Saving a Document as DOCX and PDF Using a Word VBA Macro

Amos GikundaAmos Gikunda Nov 3, 2026 869 views

Question details

The user needs a Word VBA macro that can prompt for a file destination, save the document as a DOCX, export it as a PDF using the same base filename, and automatically open the PDF upon completion.

How to Save a Document as DOCX and PDF Automatically Using Word VBA Macro
Product
Word
Device & OS
not provided
Scenario
Automating the document saving process to simultaneously generate a DOCX file for editing and a PDF file for sharing, while opening the PDF automatically so it can be added to Recent Files or quickly attached in Outlook.
Observed behavior
The user wants to configure the FileDialog, SaveAs2, and ExportAsFixedFormat methods properly in VBA to achieve the simultaneous save and auto-open functionality.
Before you start

Ensure you have the Developer tab enabled in your ribbon to access the VBA Editor, and verify that macro execution is allowed in your Trust Center settings.

Solution 1Recommended

Use ExportAsFixedFormat with OpenAfterExport Parameter

This is the most efficient method. It utilizes built-in VBA methods to save the DOCX file and simultaneously export and open the PDF without requiring additional shell commands.

By setting the OpenAfterExport parameter to True in the ExportAsFixedFormat method, the application will automatically launch the newly created PDF in your system's default PDF viewer as soon as the export finishes.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Microsoft Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the top menu, click 'Insert' and select 'Module' to create a blank workspace for your macro code.

3
Prompt for Destination

Use the 'Application.FileDialog(msoFileDialogFolderPicker)' method in your code to allow the user to select the folder where the files should be saved.

4
Save as DOCX

Once the path is selected, use the 'ActiveDocument.SaveAs2' method to save the file in standard DOCX format at the chosen destination.

5
Export and Open the PDF

Use the 'ActiveDocument.ExportAsFixedFormat' method with the same base filename. Crucially, include the argument 'OpenAfterExport:=True' to ensure the PDF opens automatically after it is saved.

Use ExportAsFixedFormat with OpenAfterExport Parameter
File Association: The PDF will automatically open in whatever application is set as the default PDF viewer on your Windows or Mac operating system.
WPS Office Macros

Automate Document Tasks with WPS Office

WPS Writer offers robust support for VBA macros, allowing you to run complex automation scripts natively. You can easily adapt your document saving and exporting macros directly within WPS Office to streamline your workflow.

  1. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
  2. 2. Enable the Developer Tools: Open WPS Writer, navigate to the settings, and enable the Developer tab to access the VBA environment.
  3. 3. Write and Execute Your Macro: Click 'VBA Editor' on the Developer tab, paste your DOCX and PDF saving script, and run it to automate your document exports.
Native support for VBA macros for seamless document automation.Highly compatible with Microsoft Word DOCX formats and macro scripts.Built-in PDF conversion engine for fast, high-quality document exports.Lightweight, secure, and completely free to use.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my PDF opening automatically after the macro finishes?

Ensure that you have included 'OpenAfterExport:=True' in your 'ExportAsFixedFormat' method. Additionally, verify that your computer has a default PDF viewer installed and properly associated with PDF files.

Can I automate the save process without the FileDialog prompt?

Yes. If you want to skip the destination prompt, you can hardcode a specific directory path (e.g., 'C:\Users\Username\Documents\MyFile.docx') directly into the 'SaveAs2' and 'ExportAsFixedFormat' functions.

How do I ensure the PDF gets added to Outlook's Recent Files?

Outlook pulls from the Windows Recent Items list. By simply opening the PDF file either via the 'OpenAfterExport:=True' trigger or the 'Documents.Open' method, the operating system typically registers the file in the Recent Items list, making it easily attachable in Outlook.

Does WPS Office support these specific VBA commands?

Yes, WPS Office Writer has excellent macro compatibility and supports standard VBA methods like 'SaveAs2' and 'ExportAsFixedFormat', allowing you to run similar automation scripts seamlessly.