Is it possible to add Repeating Section Content Control section with VBA?

前端 未结 1 1661
孤独总比滥情好
孤独总比滥情好 2021-01-28 18:30

I have created Word template with Repeating Section Rontent Control (RSCC) containing other Content Controls. Also I have excel workbook with i

相关标签:
1条回答
  • 2021-01-28 19:01

    The Word object model has a collection and object for a repeating section content control: RepeatingSectionItems and RepeatingSectionItem. The latter has two insert methods, to insert before or after the RepeatingSectionItem.

    Here's a sample that shows how to reference a repeating section content control in a document, get the first or last item and insert a new one after it.

    Sub AddRepeatingSection()
        Dim cc As Word.ContentControl
        Dim repCC As Word.RepeatingSectionItem
    
        Set cc = ActiveDocument.SelectContentControlsByTitle("RepCC").Item(1)
        Set repCC = cc.RepeatingSectionItems.Item(1)
        'Or to get the last one:
        'Set repCC = cc.RepeatingSectionItems.Item(cc.RepeatingSectionItems.Count)
        repCC.InsertItemAfter        
    End Sub
    
    0 讨论(0)
提交回复
热议问题