Change the Editability of a Content Control

Sometimes you might want to limit how a user works with a content control. Word gives you several ways to do this. For example, you can limit the text that a user can insert into a content control, force a user to insert content into a content control, or lock a content control. There are two ways that you can lock a content control. One prohibits a user from deleting the content control. Another prohibits a user from editing the content control.

You can set these restrictions programmatically. For example, you might want to prohibit a user from editing a content control based on the value that a user inserts into another control. Use the LockContentControl property to prohibit a user from deleting a content control, and use the LockContents property to prohibit a user from editing the contents of a content control.

The objects used in this sample are:

The following example uses the LockContentControl property and the LockContents property to prohibit a user from deleting or editing the content control.

Sub LockcontentControl() 
 Dim objCC As ContentControl 
 
 Set objCC = ActiveDocument.ContentControls _ 
 .Add(wdContentControlRichText) 
 
 objCC.LockcontentControl = True 
 objCC.LockContents = True 
End Sub

Using these properties with one of the events for content controls, such as the ContentControlOnExit event, gives you control over how content controls are used in documents and how users work with them.

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.