Re: Populating Content Controls with VBA



KenderFaith,

It is there, you just haven't found it yet ;-)

You can work with CCs by title, but since the title isn't unique to a CC you
have to specify which one you want to work with. Say you have three CCs
with the title "Name" and you want to work with the third one:

Sub WorkWithACCbyTitle()
Dim oCC As ContentControl
Set oCC = ActiveDocument.SelectContentControlsByTitle("Name").Item(1)
oCC.Range.Text = "Your text here."
End Sub

Still that can cause problems if you delete CCs titled "Name."

IMHO the most robust way to work with a CC is with its unique ID. This ID
remains with the CC throughout its life in the document (at least that is my
experience).

To find the unique ID, select the CC (click on it's tab) and run this code:

Sub GetUniqueID()
MsgBox Selection.ContentControls(1).ID
End Sub

Then work with the CC by ID like this:

Sub WorkWithACCbyID()
Dim oCC As ContentControl
Set oCC = ActiveDocument.ContentControls("#########") 'Replace # with actual
number values
oCC.Range.Text = "Your text there."
End Sub


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~



KenderFaith wrote:
Something that really seems to be missing with content controls is the
ability to easily dump info into them programmatically, because of the
necessity to refer to them numerically, rather than by a unique value
(like Title). Is there a simple way to use
SelectContentControlsByName (or Tag) to identify the content control
in which you wish to change the text value? The big issue with
referencing content controls by number is that if one content control
in a document is deleted, it effectively re-numbers the rest and
causes all kinds of issues...

Thanks :-)


.



Relevant Pages

  • Re: DateTime Picker
    ... > update the property on the form, you'd also need to refresh the control. ... > LOCAL cCS ... >> I didn't quite understand Anders example. ... >>>>> date field is NULL or EMPTY, or less than the MinDate property. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: DateTime Picker
    ... >> set on the DTPicker and also handling NULL or EMPTYdate values. ... >> update the property on the form, you'd also need to refresh the control. ... >> LOCAL cCS ... >> Microsoft Visual FoxPro MVP ...
    (microsoft.public.fox.programmer.exchange)
  • Re: eZdsp F2812 and PC
    ... volume control, that interfaces a PC to a DSP application using CCS. ... It is at least included in newer versions of CCS. ...
    (comp.dsp)
  • Re: eZdsp F2812 and PC
    ... volume control, that interfaces a PC to a DSP application using CCS. ... It is at least included in newer versions of CCS. ...
    (comp.dsp)