G
Greg Maxey
The Word Developer's Reference states that each content control has its own
unique ID so that you can read from it and write to it.
It is true, each has its own ID. You can get the ID of a selected CC using
this simple code:
Sub GetUniqueID()
MsgBox Selection.ContentControls(1).ID
End Sub
What I can't figure out is a direct method of referring to a CC by its
unique ID in code. For example if I have a collection of CCs and 1 of them
has the ID 123456. How would I write a statement like:
Sub Test()
Dim myCC as ContentControl
Set myCC = ActiveDocument.ContentControls (?????)
With myCC
'Do something
End With
End Sub
If I give my CC as unique "Title" or "Tag" then I can use the
SelectContentControlbyTitle or SelectContentControlbyTag like this:
Sub Test()
Dim myCC as ContentControl
Set myCC = ActiveDocument.SelectContentControlsByTitle("MyTitle").Item(1)
With myCC
'Do something
End With
End Sub
but there isn't a SelectContentControlbyID :-(
It seems that since titles and tags are neccessarily unique to a CC then
there should be a direct method of referring to a CC by it ID like methods
for Title and Tag. All I have been able to come up with so far is looping
through the collection like this:
Sub Test()
Dim oCC1 As ContentControl
Dim myCC As ContentControl
For Each oCC1 In ActiveDocument.ContentControls
If oCC1.ID = 123456 Then
Set myCC = oCC1
Exit For
End If
Next
With myCC
'Do something
End With
End Sub
Am I missing something?
unique ID so that you can read from it and write to it.
It is true, each has its own ID. You can get the ID of a selected CC using
this simple code:
Sub GetUniqueID()
MsgBox Selection.ContentControls(1).ID
End Sub
What I can't figure out is a direct method of referring to a CC by its
unique ID in code. For example if I have a collection of CCs and 1 of them
has the ID 123456. How would I write a statement like:
Sub Test()
Dim myCC as ContentControl
Set myCC = ActiveDocument.ContentControls (?????)
With myCC
'Do something
End With
End Sub
If I give my CC as unique "Title" or "Tag" then I can use the
SelectContentControlbyTitle or SelectContentControlbyTag like this:
Sub Test()
Dim myCC as ContentControl
Set myCC = ActiveDocument.SelectContentControlsByTitle("MyTitle").Item(1)
With myCC
'Do something
End With
End Sub
but there isn't a SelectContentControlbyID :-(
It seems that since titles and tags are neccessarily unique to a CC then
there should be a direct method of referring to a CC by it ID like methods
for Title and Tag. All I have been able to come up with so far is looping
through the collection like this:
Sub Test()
Dim oCC1 As ContentControl
Dim myCC As ContentControl
For Each oCC1 In ActiveDocument.ContentControls
If oCC1.ID = 123456 Then
Set myCC = oCC1
Exit For
End If
Next
With myCC
'Do something
End With
End Sub
Am I missing something?