是否可以在VBA中添加“重复节内容控制"部分? [英] Is it possible to add Repeating Section Content Control section with VBA?

查看:139
本文介绍了是否可以在VBA中添加“重复节内容控制"部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了包含重复节内容控制(RSCC)的Word模板,其中包含其他 Content Controls .我也有excel工作簿,其中的信息应转到提到的Word模板.我正在尝试做的事情是创建一个宏,该宏将用Excel工作簿中的选定行(每一行到新的RSCC部分)中的信息填充Word模板.

I have created Word template with Repeating Section Rontent Control (RSCC) containing other Content Controls. Also I have excel workbook with information which should go to mentioned Word template. The thing I am trying to do is to create macro which would fill Word template with information from selected rows in Excel workbook (each row to new RSCC section).

我有一个很好的主意,除了一件事-我无法弄清楚如何编写宏,这会在重复节内容控制中添加另一节.

I have quite good idea how to do that, except one thing- I cannot figure out how to write macro which would add another section to Repeating Section Content Control.

我正在添加说明我正在尝试做的事情:

I am adding illustrations of what I am trying to do:

问题是,我找不到使用VBA执行相同操作的代码.我已经尝试了录制过程,但是录制的宏为空(?!).

Problem is, that I cannot find code to do the same thing with VBA. I have tried recording process, but recorded macro is empty (?!).

寻找答案,我发现此线程在StackOverflow中,它会问与我类似的问题,但据我所知,它或多或少都没有答案.将此线程中的注释转发到

Looking for answer I have found this thread in StackOverflow, 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, but I did not find solution to this problem (or at least I did not understand clearly how should I approach it).

由于一个线程将近5年,另外2年.我的问题是,是否甚至可以通过VBA向RSCC添加其他部分?也许有人在过去一年左右的时间里找到了一种方法?

Since one thread is almost 5 years old, another 2 years old. My question is it even possible to add another section to RSCC with VBA? Maybe somebody found a way to do this in the past year or so?

推荐答案

Word对象模型具有用于重复节内容控件的集合和对象:RepeatingSectionItemsRepeatingSectionItem.后者有两种插入方法,可以在RepeatingSectionItem之前或之后插入.

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

这篇关于是否可以在VBA中添加“重复节内容控制"部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆