PDA

View Full Version : [SOLVED:] Simple - change value of content control



MINCUS1308
10-01-2014, 09:49 AM
I have a word document with a number of tables.
In my tables I have a variety of content control fields.
In the event of my document closing, I would like to change the value in one of the controls. (a plain text content control Titled:"'Controlled")

I know it is a simple task but I cant find the correct solution online.
The code below doesn't work.


Private Sub Document_Close()

ActiveDocument.ContentControls("Controlled").Range.Text = Now()
ThisDocument.Save

End Sub


Any help would be greatly appreciated.

MINCUS1308
10-01-2014, 10:06 AM
Through Trial and Error I was able to make the following code work.


Private Sub Document_Close()

Set obj = ActiveDocument.ContentControls(2)
obj.Range.Text = Now()

ThisDocument.Save

End Sub

I would prefer to reference the control by title but I was unable to figure it out.

gmaxey
10-01-2014, 12:52 PM
ActiveDocument.SelectContentControlsByTitle.Item(1).Range.Text = Now()