繁体   English   中英

将Builiding Block中的Table插入Word文档中的指定位置。

[英]Insert Table from Builiding Block in specified location in the word document.

我想插入定义为构件块的表。 我将内容控件放置在文档中的指定位置,并通过“ selectcontetcontrolsbytag”对其进行引用。 不幸的是,将表插入到conentcontrol时,它将转换为RichText。 这是我的代码:

ThisDocument.SelectContentControlsByTag("TermsConditions").Item(1).Range = _
ActiveDocument.AttachedTemplate.BuildingBlockTypes.Item(wdTypeTables).Categories.Item("Terms and Conditions Translation").BuildingBlocks.Item("Terms and Conditions Eng")

您能否以适当的代码帮助我,以便在指定位置插入构件。 当用户从用户窗体,组合框等中选择其他项目时,我也希望此构建基块被另一个替换。

我的问题的完整解决方案是:

  1. Cindy Meister提出的解决方案替换内容控件中的内容:
  2. 为了更改内容控件“ TermsConditions”中的内容,我添加了以下代码:

    如果doc.SelectContentControlsByTag(“ TermsConditions”)。Item(1).Range.Text <> doc.SelectContentControlsByTag(“ TermsConditions”)。Item(1).PlaceholderText然后是doc.SelectContentControlsByTag(“ TermsConditions”)。Item(1)。 Range.Cut Else End If

我不确定“将其转换为RTF”是什么意思...

插入BuildingBlock的公认方法是使用向您传递目标Range对象的BuildingBlock.Insert方法。 例如(基于您的代码示例):

Dim doc as Word.Document
Dim rngTarget as Word.Range
Set doc = ActiveDocument
Set rngTarget = doc.SelectContentControlsByTag("TermsConditions").Item(1).Range 
doc.AttachedTemplate.BuildingBlockTypes.Item(wdTypeTables).Categories.Item("Terms and and Conditions Translation").BuildingBlocks.Item("Terms and Conditions Eng").Insert rngTarget, true

看一下《 VBA语言参考》中的示例。

另外,您不应在代码中使用ThisDocument,而应使用ActiveDocument。 (更好的是,声明一个Document对象,为它分配ActiveDocument,然后使用它。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM