How do I limit the number of characters when using Rich Text Content Control in MS Word?

135 Views Asked by At

As far as I know, it is not possible through the Word GUI.

I know it is simple using Text Form Fields. But I don't like how the fields are highlighted with a grey box (that does not seem to go away).

So I am not stuck to using Rich Text Content Controls, but I am ignorant is making the Text Form Fields look nice.

My fields have the appearance of YYYY-MM-DD-PARTID.

1

There are 1 best solutions below

0
Eugene Astafiev On

The ContentControl class doesn't provide anything for that. The best what you could do is to use a placeholder text to let users know how the data format should look like. The ContentControl.SetPlaceholderText method sets the placeholder text that displays in the content control until a user enters their own text.

For example, with a drop down control you may use the following code:

Dim objCC As ContentControl 
Dim objMap As XMLMapping 
 
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlDropdownList) 
objCC.Title = "My Favorite Animal" 
objCC.SetPlaceholderText , , "Select your favorite animal " 
 
'List entries 
objCC.DropdownListEntries.Add "Cat" 
objCC.DropdownListEntries.Add "Dog" 
objCC.DropdownListEntries.Add "Horse" 
objCC.DropdownListEntries.Add "Monkey" 
objCC.DropdownListEntries.Add "Snake" 
objCC.DropdownListEntries.Add "Other"

For entering dates you can use the ContentControl.DateDisplayFormat property which returns or sets a string that represents the format in which dates are displayed.

Dim objCC As ContentControl 
 
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlDate) 
 
objCC.Title = "Start Date" 
objCC.DateDisplayFormat = "MMMM d, yyyy" 
objCC.DateStorageFormat = wdContentControlDateStorageDate 
objCC.Range.Text = "January 1, 2023"