How to Automate Print-to-File Saving in Word VBA
Question details
The user needs to automate a Word macro so that when it opens the printer dialog, it automatically saves the resulting PRN file to a specific folder rather than defaulting to the Documents directory.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating file generation via VBA macros to streamline bulk printing or file conversion processes without user interaction.
- Observed behavior
- The macro correctly triggers the print action but halts at the printer dialog, defaulting to the Documents directory and requiring a manual click and path selection to save the PRN file.
Ensure you have the Developer tab enabled in your word processor and have basic familiarity with the Visual Basic Editor before modifying and running macro scripts.
Use the OutputFileName Argument in the PrintOut Method
You can completely bypass the print dialog and automate the PRN file path by utilizing the OutputFileName argument directly within your VBA PrintOut command.
By default, calling a print-to-file command without an explicit path will prompt the user to choose a destination. By explicitly defining the OutputFileName parameter in VBA, the file is saved automatically.
Ensure the destination folder already exists on your system; otherwise, the macro will result in a runtime error.
Press Alt + F11 on your keyboard to open the VBA Editor.
Right-click your project in the Project Explorer, select 'Insert', and click 'Module' to create a new script area.
Enter the following command into your macro: ActiveDocument.PrintOut PrintToFile:=True, OutputFileName:="C:\YourTargetFolder\YourFileName.prn"
Press F5 or click the 'Run' button. The document will be sent to the current default printer driver and saved directly as a PRN file in the specified directory without opening a save dialog.

Use Document.ExportAsFixedFormat for PDF Creation
If generating a PRN file is not strictly necessary and you only need a fixed layout format, exporting directly to PDF using ExportAsFixedFormat is highly recommended and easier to automate.
Configure a Local Port for the Printer Driver
For scenarios where VBA adjustments are restricted, you can modify the Windows Printer settings to permanently route all print jobs to a fixed file path.
Automate File Generation Easily with WPS Writer
WPS Office offers comprehensive VBA and macro compatibility, allowing you to write, edit, and seamlessly execute scripts for automating print jobs and PDF exports. It's a lightweight, efficient tool designed to handle your professional automation tasks.
- 1. Download and Install: Download WPS Office Free from the official website and install it on your computer.
- 2. Enable the Developer Tab: Open WPS Writer, go to the settings to enable the Developer tab, giving you access to macro tools.
- 3. Launch the VBA Editor: Click on 'Visual Basic' in the Developer tab or press Alt+F11 to open the VBA Editor.
- 4. Input and Run Your Macro: Paste your PrintOut or ExportAsFixedFormat code and run it to automatically save your files to the desired folder.

Frequently Asked Questions
Can I specify the output path directly in the PrintOut method for PRN files?
Yes, you can bypass the manual save prompt by setting PrintToFile:=True and providing a full file path using the OutputFileName argument in your ActiveDocument.PrintOut command.
What is the difference between ExportAsFixedFormat and PrintToFile?
ExportAsFixedFormat natively creates a standardized PDF or XPS file without relying on external printer drivers. PrintToFile, however, relies on the active printer's driver to generate a PRN file containing specific printer control instructions.
How do I avoid getting a runtime error when using OutputFileName?
Runtime errors usually occur if the target folder specified in your OutputFileName path does not exist, or if the application lacks administrative privileges to write to that directory. Always ensure the folder is created before running the macro.




