logo
search
Document Editing Problems

How to Add 30 and 90 Days to a Word Date Picker Using VBA

Tauseeq MagsiTauseeq Magsi Sep 27, 2026 868 views

Question details

The user needs a way to automatically calculate and display future dates (30 and 90 days later) based on a source date selected in a Word date picker content control.

How to Add 30 and 90 Days to a Word Date Picker Using VBA
Product
Word
Device & OS
not provided
Scenario
Setting up a dynamic document or contract where follow-up deadlines (30 and 90 days) must update instantly when an initial date is chosen.
Observed behavior
The user currently lacks an automated method to update linked date fields and needs a VBA macro solution to handle the calculation and formatting automatically upon selecting the source date.
Before you start

Ensure that the Developer tab is enabled in your word processor's ribbon, as you will need it to insert Content Controls and access the Visual Basic for Applications (VBA) editor.

Solution 1Recommended

Use a Document_ContentControlOnExit VBA Macro

Create a VBA macro that triggers when you finish interacting with the source date picker, automatically calculating and populating the future dates in designated output controls.

This method requires creating one input Date Picker content control and two output content controls. The macro calculates the target dates based on the input and can preserve your preferred date format automatically.

1
Insert the Content Controls

Go to the Developer tab. Insert a Date Picker content control and click 'Properties' to set its Title to 'Date1'. Insert two additional plain text or date content controls, setting their titles to 'Date2' and 'Date3'.

2
Open the VBA Editor

Press Alt + F11 to launch the Visual Basic for Applications (VBA) editor. In the Project Explorer pane on the left side, double-click on 'ThisDocument' to open the document's code window.

3
Add the Macro Code

Create a Document_ContentControlOnExit sub-routine. Add an If statement to check if the exited control's Title is 'Date1'. If true, set the value of 'Date2' to the selected date + 30, and 'Date3' to the selected date + 90. You can use the DateDisplayFormat property to maintain formatting.

4
Save as a Macro-Enabled Document

Go to File > Save As, and choose 'Word Macro-Enabled Document (*.docm)' from the file type dropdown. This ensures your script is saved and will run the next time the file is opened.

Use a Document_ContentControlOnExit VBA Macro
Enable Macros: For the date calculation to work, ensure that macros are enabled in your software's Trust Center settings. The calculation triggers only after you click outside the Date1 control.
Advanced Document Automation

Automate Date Calculations Easily with WPS Writer

WPS Office provides robust support for VBA macros and Content Controls, allowing you to implement dynamic date calculations seamlessly without needing expensive software.

  1. 1. Enable the Developer Tab: Open WPS Writer, access the settings menu, and enable the Developer tab to gain access to advanced document controls.
  2. 2. Insert Controls and Code: Use the Developer tab to insert your Date Picker and Text content controls, then press Alt + F11 to launch the built-in VBA editor and paste your script.
  3. 3. Save and Execute: Save your document as a .docm file. WPS Writer will flawlessly execute your Document_ContentControlOnExit macro to automate your date fields.
Full support for VBA macros and .docm filesSeamless compatibility with Microsoft Word document formatsLightweight, fast, and free to use for everyday tasks
QA img-9

Frequently Asked Questions

Why is the VBA macro not running when I select a new date?

The 'Document_ContentControlOnExit' event only fires when you move your cursor out of the 'Date1' content control. Click anywhere else in the document after selecting the date to trigger the macro. Also, double-check that macros are enabled in your Trust Center settings.

Can I format the output dates differently from the input date?

Yes. In your VBA code, you can use the VBA Format function (e.g., Format(newDate, "MMMM d, yyyy")) before assigning the value to Date2 and Date3, or you can utilize the CCtrl.DateDisplayFormat property if the output controls are also date pickers.

How can I subtract days instead of adding them?

You can easily modify the VBA math. Instead of adding a number (e.g., Date + 30), change the plus sign to a minus sign (e.g., Date - 30) in your VBA script to calculate past dates.