VBA & Macro Problems

How to Automate Print-to-File Saving in Word VBA

Elise WilliamsElise Williams Nov 2, 2026 868 views

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.

How to Automate Print-to-File Saving in Word VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Visual Basic Editor

Press Alt + F11 on your keyboard to open the VBA Editor.

2
Insert a New Module

Right-click your project in the Project Explorer, select 'Insert', and click 'Module' to create a new script area.

3
Write the PrintOut Code

Enter the following command into your macro: ActiveDocument.PrintOut PrintToFile:=True, OutputFileName:="C:\YourTargetFolder\YourFileName.prn"

4
Run the Macro

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 the OutputFileName Argument in the PrintOut Method
Path Verification: Always double-check that the file path string is correct and that your application has write permissions to that specific folder.
Powerful VBA Support

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. 1. Download and Install: Download WPS Office Free from the official website and install it on your computer.
  2. 2. Enable the Developer Tab: Open WPS Writer, go to the settings to enable the Developer tab, giving you access to macro tools.
  3. 3. Launch the VBA Editor: Click on 'Visual Basic' in the Developer tab or press Alt+F11 to open the VBA Editor.
  4. 4. Input and Run Your Macro: Paste your PrintOut or ExportAsFixedFormat code and run it to automatically save your files to the desired folder.
Full support for standard Word VBA macros and syntaxSeamlessly export documents directly to PDF using built-in methodsExcellent compatibility with Microsoft Office .docm and .dotm macro-enabled formatsLightweight application that runs smoothly even on older devices
microsoft office alternative - wps office

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.