Link to home
Start Free TrialLog in
Avatar of etech0
etech0Flag for United States of America

asked on

Refer to Plain Text Content Control in Word

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.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of etech0

ASKER

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?
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

Avatar of etech0

ASKER

How do I give it a unique Title?
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
Avatar of etech0

ASKER

I only have to do this once, and it will get stored in the document?
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of etech0

ASKER

That did it. Thanks!