logo
search
Document Editing Problems

How to Add Date Picker Content Controls to Word Dates Using VBA

Elise WilliamsElise Williams Oct 21, 2026 868 views

Question details

The user needs to locate specific long-format text dates in a document and replace them with interactive Date Picker content controls using a custom format.

How to Add Date Picker Content Controls to Word Dates Using VBA
Product
Word
Device & OS
not provided
Scenario
Automating the conversion of static text dates into functional date picker controls using VBA wildcard searches without missing specific months.
Observed behavior
A programmatic solution is required to accurately find dates like 'Tuesday, April 18, 2023', ensuring all months including January, June, and July are properly matched and converted to wdContentControlDate elements.
Before you start

Ensure that the Developer tab is enabled in your Word ribbon to access the Visual Basic editor, and create a backup copy of your document before running bulk replacement macros to prevent accidental data loss.

Solution 1Recommended

Use VBA Macro with Wildcard Searching

Run a custom VBA macro designed to identify specific date patterns using wildcards and replace them with Date Picker controls.

This macro utilizes Word's advanced wildcard search capabilities to accurately detect long-format dates (Day, Month Date, Year) and wraps them in an interactive Date Picker. The specific search string [FMSTW][a-z]{1,}, [ADFJMNOS][a-z]{1,} [0-9]{1,2}, [0-9]{4} explicitly includes the letter 'J' to ensure months like January, June, and July are not skipped during the search process.

1
Open the VBA Editor

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

2
Insert a New Module

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

3
Paste the Macro Code

Copy and paste the following script into the module window: Sub DateToDatePicker() Dim CC As ContentControl Dim rg As Range Set rg = ActiveDocument.Range With rg.Find .MatchWildcards = True .Text = "[FMSTW][a-z]{1,}, [ADFJMNOS][a-z]{1,} [0-9]{1,2}, [0-9]{4}" While .Execute Set CC = ActiveDocument.ContentControls.Add(Type:=wdContentControlDate, Range:=rg) CC.DateDisplayFormat = "dddd, MMMM d, yyyy" rg.Collapse wdCollapseEnd rg.Move wdCharacter, 1 Wend End With End Sub

4
Run the Macro

Close the VBA editor to return to your document. Press ALT + F8 to open the Macros dialog box, select DateToDatePicker from the list, and click Run.

Testing First: Always test wildcard macros on a sample document first to ensure the date pattern matches your exact text formatting and doesn't affect unintended content.
Simplify Document Forms

Insert Date Pickers Easily with WPS Writer

If you prefer avoiding complex VBA scripts, WPS Office provides an intuitive Developer tab where you can quickly insert, customize, and manage Date Picker content controls directly from the user interface.

  1. 1. Enable Developer Tools: Open your document in WPS Writer. Go to Menu > Options > Customize Ribbon and check the Developer box to reveal the Developer tab.
  2. 2. Highlight Target Area: Select the existing text date or click the precise location in your document where you want the interactive calendar to appear.
  3. 3. Insert Content Control: Navigate to the Developer tab on the top ribbon and click the Date Picker Content Control icon.
  4. 4. Configure Date Format: With the control selected, click Properties in the Developer tab to set your preferred display format, such as 'dddd, MMMM d, yyyy'.
Fully compatible with Microsoft Word (.docx) formats and form controlsUser-friendly Developer tools for visual form creationLightweight application that runs smoothly on any systemNo coding required for standard content control insertion
microsoft office alternative - wps office

Frequently Asked Questions

Why does my VBA macro skip dates in January, June, and July?

If your wildcard search string omits the letter 'J' in the month section (e.g., [ADFMNOS]), it will automatically skip any month starting with that letter. Update your pattern to include 'J' like this: [ADFJMNOS][a-z]{1,}.

How do I ensure the wildcard search finds the exact date format?

The wildcard text must mirror your document's specific date structure. For 'Tuesday, April 18, 2023', the string [FMSTW][a-z]{1,}, [ADFJMNOS][a-z]{1,} [0-9]{1,2}, [0-9]{4} explicitly looks for a capitalized day name, a comma, a capitalized month name, a 1- or 2-digit date, a comma, and a 4-digit year.

Can I change the display format of the inserted date picker control via VBA?

Yes. In your macro, you can set the DateDisplayFormat property to your preferred layout. For example, setting CC.DateDisplayFormat = "dddd, MMMM d, yyyy" ensures the date displays cleanly as 'Tuesday, April 18, 2023' after a user selects a date.

What does wdContentControlDate do in Word VBA?

It is a built-in constant in Word VBA that specifies the exact type of content control to generate. When used with ContentControls.Add, it commands the application to insert an interactive calendar picker rather than a standard text box or drop-down list.