
There is no built-in word limit property for ActiveX text boxes in Word documents. However, you can write VBA code to achieve this. Here is an example:
- Insert an ActiveX textbox into your Word document.
- Right-click the textbox and select "View Code" to open the VBA editor.
- Paste the following code into the editor:
Private Sub TextBox1_Change()
Dim wordCount As Integer
wordCount = Len(Trim(TextBox1.Value)) - Len(Replace(Trim(TextBox1.Value), " ", "")) + 1
If wordCount > 10 Then 'replace 10 with the desired word limit
Dim startIndex As Integer
startIndex = InStrRev(TextBox1.Value, " ", 10)
MsgBox "You have reached the maximum word limit of 10", vbInformation, "Word Limit Exceeded"
TextBox1.Value = Left(TextBox1.Value, startIndex)
End If
End Sub
Note: In the above code, change "TextBox1" to match the name of your ActiveX textbox.
This code will limit the number of words to 10. Replace "10" in the code with the desired word limit. When the user types in the textbox and enters more than the specified number of words, a message box will appear and further text input will be prevented.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.