none
Repeating Section Content Control "Placeholder text" RRS feed

  • Question

  • There does not appear to be any way to set the placeholder text on a repeating section content control. In fact it appears that what looks like placeholder text in a repeating section content control is something entirely different.

    I open a new document in Word 2013 and type "Test" then hit enter.  Next I run this code:

    Sub Test()
    Dim oCC As ContentControl
    Dim oPHT As Object
      'Add a new repeating section CC.
      Set oCC = Selection.Range.ContentControls.Add(wdContentControlRepeatingSection, Selection.Range)
      'It looks like it is showing placeholder text, but apparently not.
      If oCC.ShowingPlaceholderText Then
        Debug.Print oCC.PlaceholderText
      End If
      'Attempt to set placeholder text to a range.
      oCC.SetPlaceHolderText , ActiveDocument.Words(1)
      Set oPHT = oCC.PlaceholderText
      Debug.Print oPHT.Value
      'It set, but the CC looks the same "Enter any ..."
      'Attempt to set placeholder text to a string.
      oCC.SetPlaceHolderText Text:="Test"
      Set oPHT = oCC.PlaceholderText
      Debug.Print oPHT.Value
      'Again it set, but the CC looks the same "Enter any ..." :-(
      If oCC.ShowingPlaceholderText Then
        Debug.Print oCC.PlaceholderText
      End If
    End Sub
    

    Does anyone know what the default  "Enter any content that you want to repeat ..." really is and if there is a programmatic way to alter/define it?

    Thank!


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Tuesday, May 27, 2014 1:18 PM

Answers

  • I had a look around. 

    When you create the repeating content control, the control has no placeholder text. If you set the placeholder text, AFAICS it is never used. If you do not set the placeholder text, you'll see an error when you try to access it.

    Each repeating section has its own placeholder text. However, in the object model, the RepeatingSectionItem does not allow you to set or retrieve that placeholder text. 

    If you set the placeholder text in design mode, it is for that RepeatingSectionItem only. If you then insert a new RepeatingSectionItem in the UI or via the Object model, the existing (selected/specified) RepeatingSectionItem's placeholder text is copied to the new item. In the XML, it is a copy - i.e., the old item and the new item do not point to the same placeholder text in the Glossary Document - there is a different docPart for each one.

    On the business of setting the item placeholder texts programmatically, I cnanot currently see an easy way via the object model
     a. the repeating section item does not have the necessary properties
     b. as far as I know, if you attempt to .toggledesignmode, VBA halt or breaks out of the routine
     c. the WordOpenXML of the range of the repeating item is no help (does not contain the placeholder text)
     d. I got an "A file error has occured" message when I attempted to access the WordOpenXML of the parent content control.

    So I suspect the only way to do it is probably by saving as OOXML, closing, fixing the OOXML and re-opening. 
    As usual, there is probably more to be discovered :-)

    Update:
    Just for interest, I had a look at switching to design mode and back. As a last resort you could start with something like this:

    Sub Macro1()
    Application.OnTime Now + TimeValue("00:00:01"), "changeIt"
    ActiveDocument.ToggleFormsDesign
    End Sub
    
    Sub changeIt()
    ActiveDocument.ContentControls(1).RepeatingSectionItems(2).Range.Select
    ' in a real situation, you would probably need to figure out how and
    ' where to save the existing content, which can be rich.
    ' neither range.text = "value" nor selection.text = "value" is enough
    ' Have to use TypeText
    Selection.TypeText "a new placeholder"
    ActiveDocument.ToggleFormsDesign
    End Sub

    Peter Jamieson


    Thursday, May 29, 2014 9:39 AM

All replies

  • As far as I know, it is the text in the .range of the contentcontrol.repeatingsectionitems(1). If you modify the text, then add a section, I think the text will be replicated in the next "empty" repeatingsectionitem, but if you want it to be grey text, you'll probably have to colour the range grey.

    Peter Jamieson

    Wednesday, May 28, 2014 12:22 AM
  • Peter,

    I'm just trying to understand what it is ;-).  It looks like placeholder text, it can be modified like placeholder text can using the designer control, but it really isn't PHT.  Seems odd the you can set PHT in a repeating section controls programmatically but it doesn't appear anywhere.

    Thanks!

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Wednesday, May 28, 2014 12:38 AM
  • Well, I notice that word tends to create a new copy of the placeholder/default text for each repeating item (in the XML glossary document) and can have the. "Placeholder text is displaying " attribute set on a per-item basis. Also, if the first item doesn't have a placeholder text, trying to retrieve the placeholder for the control as a whole raises an error. But I won't be able to look further for a day or so.

    Peter Jamieson

    Wednesday, May 28, 2014 1:41 AM
  • I had a look around. 

    When you create the repeating content control, the control has no placeholder text. If you set the placeholder text, AFAICS it is never used. If you do not set the placeholder text, you'll see an error when you try to access it.

    Each repeating section has its own placeholder text. However, in the object model, the RepeatingSectionItem does not allow you to set or retrieve that placeholder text. 

    If you set the placeholder text in design mode, it is for that RepeatingSectionItem only. If you then insert a new RepeatingSectionItem in the UI or via the Object model, the existing (selected/specified) RepeatingSectionItem's placeholder text is copied to the new item. In the XML, it is a copy - i.e., the old item and the new item do not point to the same placeholder text in the Glossary Document - there is a different docPart for each one.

    On the business of setting the item placeholder texts programmatically, I cnanot currently see an easy way via the object model
     a. the repeating section item does not have the necessary properties
     b. as far as I know, if you attempt to .toggledesignmode, VBA halt or breaks out of the routine
     c. the WordOpenXML of the range of the repeating item is no help (does not contain the placeholder text)
     d. I got an "A file error has occured" message when I attempted to access the WordOpenXML of the parent content control.

    So I suspect the only way to do it is probably by saving as OOXML, closing, fixing the OOXML and re-opening. 
    As usual, there is probably more to be discovered :-)

    Update:
    Just for interest, I had a look at switching to design mode and back. As a last resort you could start with something like this:

    Sub Macro1()
    Application.OnTime Now + TimeValue("00:00:01"), "changeIt"
    ActiveDocument.ToggleFormsDesign
    End Sub
    
    Sub changeIt()
    ActiveDocument.ContentControls(1).RepeatingSectionItems(2).Range.Select
    ' in a real situation, you would probably need to figure out how and
    ' where to save the existing content, which can be rich.
    ' neither range.text = "value" nor selection.text = "value" is enough
    ' Have to use TypeText
    Selection.TypeText "a new placeholder"
    ActiveDocument.ToggleFormsDesign
    End Sub

    Peter Jamieson


    Thursday, May 29, 2014 9:39 AM