是否可以使用 VBA 添加 Repeating Section Content Control 部分?
Is it possible to add Repeating Section Content Control section with VBA?
我使用 重复部分 Rontent 控件 (RSCC) 创建了包含其他 内容控件 的 Word 模板。我还有 excel 工作簿,其中包含应该转到提到的 Word 模板的信息。我想做的是创建宏,用 Excel 工作簿中选定行的信息填充 Word 模板(每一行到新的 RSCC 部分)。
我很清楚如何做到这一点,除了一件事 - 我不知道如何编写宏来将另一个部分添加到 重复部分内容控制 。
我正在添加我正在尝试做的事情的插图:
问题是,我找不到用 VBA 做同样事情的代码。我试过录制过程,但是录制的宏是空的(?!)。
寻找答案我找到了 this thread in Whosebug, it ask similar question to mine, but it was more or less unanswered to my understanding. Comment in this thread forwarded to old thread in Microsoft forum,但我没有找到解决这个问题的方法(或者至少我不清楚我应该如何处理它)。
因为一个线程快 5 岁了,另一个 2 岁了。我的问题是,是否可以使用 VBA 向 RSCC 添加另一个部分?也许有人在过去一年左右找到了这样做的方法?
Word 对象模型有一个用于重复节内容控件的集合和对象:RepeatingSectionItems
和 RepeatingSectionItem
。后者有两种插入方法,在RepeatingSectionItem
.
之前或之后插入
下面的示例展示了如何引用文档中的重复部分内容控件、获取第一个或最后一个项目并在其后插入一个新项目。
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
我使用 重复部分 Rontent 控件 (RSCC) 创建了包含其他 内容控件 的 Word 模板。我还有 excel 工作簿,其中包含应该转到提到的 Word 模板的信息。我想做的是创建宏,用 Excel 工作簿中选定行的信息填充 Word 模板(每一行到新的 RSCC 部分)。
我很清楚如何做到这一点,除了一件事 - 我不知道如何编写宏来将另一个部分添加到 重复部分内容控制 。
我正在添加我正在尝试做的事情的插图:
问题是,我找不到用 VBA 做同样事情的代码。我试过录制过程,但是录制的宏是空的(?!)。
寻找答案我找到了 this thread in Whosebug, it ask similar question to mine, but it was more or less unanswered to my understanding. Comment in this thread forwarded to old thread in Microsoft forum,但我没有找到解决这个问题的方法(或者至少我不清楚我应该如何处理它)。
因为一个线程快 5 岁了,另一个 2 岁了。我的问题是,是否可以使用 VBA 向 RSCC 添加另一个部分?也许有人在过去一年左右找到了这样做的方法?
Word 对象模型有一个用于重复节内容控件的集合和对象:RepeatingSectionItems
和 RepeatingSectionItem
。后者有两种插入方法,在RepeatingSectionItem
.
下面的示例展示了如何引用文档中的重复部分内容控件、获取第一个或最后一个项目并在其后插入一个新项目。
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