We help IT Professionals succeed at work.

Refer to Plain Text Content Control in Word

etech0
etech0 asked
on
I have a plain text content control in Word where a user enters data.
Can I reference that data later in the document?
The way I have it now, I bookmarked the control, but then the referenced data comes up with a control around it.
Is there a better way?

Thanks.
Comment
Watch Question

GrahamSkanRetired
Top Expert 2012

Commented:
Without VBA, I don't think so. But does it matter? The control is only visible if clicked on, and doesn't appear in print.

Author

Commented:
I know, but I don't want anyone to type in it, and the control makes it look like it should be typed in.
How can I do this with VBA?
GrahamSkanRetired
Top Expert 2012

Commented:
Give the content control, a unique Title, and put this code in the ThisDocument module:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim rng As Range
If ContentControl.Title = "MyContentControl" Then
    Set rng = ActiveDocument.Bookmarks("MyBookmark").Range
    rng.Text = ContentControl.Range.Text
    ActiveDocument.Bookmarks.Add "MyBookmark", rng
End If
End Sub

Open in new window

Author

Commented:
How do I give it a unique Title?
GrahamSkanRetired
Top Expert 2012

Commented:
Select the control.
Click on the 'Design Mode' icon in the Controls group on the Developer tab.
Right-click on right-hand 'wing' of the control and choose properties. Enter the Title in the box.

Note that you can give more than one control the same title, so it is up to you to ensure that it is unique.

Note also that you can use the Tag property in the same way

Author

Commented:
I only have to do this once, and it will get stored in the document?
Retired
Top Expert 2012
Commented:
You can put it in the ThisDocument module of the document's template and it will work, but not if the document loses touch with the template.

You can put it in same module of the document itself and store the document as a .docm. Then the code will be in the document file, and doesn't need to refer to its template.

Author

Commented:
That did it. Thanks!