How to Validate Word Form Fields Before Saving as PDF
Question details
The user needs a method to ensure all required fields in a Word form are filled out and validated before the document is allowed to be saved or exported as a PDF.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Exporting a completed Word form to a PDF while ensuring data integrity and preventing blank or invalid form submissions.
- Observed behavior
- Without proper rules in place, the document might save or export to PDF without verifying if essential form fields and content controls are completed correctly, resulting in incomplete records.
Ensure your document has Developer tools enabled so you can access content controls and VBA macros. Saving your document as a macro-enabled format (.docm) is required if you plan to use VBA scripts for validation.
Use VBA and the DocumentBeforeSave Event
The most robust way to validate form fields is by utilizing a VBA macro that intercepts the save action and checks every required content control before creating the PDF.
By utilizing the DocumentBeforeSave event, you can prevent users from saving or printing incomplete forms. VBA loops through all fields, verifying that none are blank or left at their default values.
Go to File > Options > Customize Ribbon and check the 'Developer' box in the right pane to enable macro and control tools.
Press Alt + F11 to open the Visual Basic for Applications editor. In the Project Explorer pane on the left, double-click 'ThisDocument'.
Insert a Private Sub DocumentBeforeSave event procedure into the code window. Write a loop to iterate through the form's ContentControls collection.
Within the loop, add If/Then logic to check for blank, default, or invalid text values in each control. If invalid data is found, prompt the user with a message box and set Cancel = True to halt the save or PDF export.
Once validation passes (no invalid fields trigger the cancel command), allow the save to proceed, or trigger a specific PDF export function to finalize the document.

Configure Basic Form-Field Properties
For simpler forms using legacy tools, you can use built-in form field properties to enforce basic data types without writing complex VBA code.
Edit Forms and Export to PDF with WPS Office
WPS Writer offers an intuitive interface for managing documents with form controls and seamless one-click export to PDF, ensuring your important data is captured and shared perfectly.
- 1. Open your document: Launch WPS Writer and open your form document.
- 2. Navigate to the PDF tool: Go to the 'Menu' or the 'Tools' tab and select 'Export to PDF'.
- 3. Configure and export: Configure your preferred export settings, choose your save path, and click 'Export' to create your final PDF.

Frequently Asked Questions
Can I validate rich-text controls the same way as dropdowns?
Yes. Using VBA, you can loop through both rich-text controls and dropdowns by checking the .Type property of the ContentControl object and verifying their .Range.Text values against your required criteria.
How do I remove the content control boxes before saving to PDF?
You can write a macro that runs right before exporting the PDF. This macro should copy the document, loop through and delete the content control bounds (keeping the typed text intact), and then save that clean temporary version as the PDF.
Why did my document save even though validation failed?
If you are using VBA for validation, ensure your macro security settings allow the script to run. Additionally, you must explicitly set the variable 'Cancel = True' inside the DocumentBeforeSave event when a required field is found empty.
Are Word content controls compatible with legacy form fields?
While you can technically mix legacy form fields and modern content controls in the same document, it is highly recommended to stick to one type (preferably modern content controls) for easier validation and data binding.




