获取内容'来自丰富的文本内容控制

发布于 2025-02-09 07:34:43 字数 563 浏览 1 评论 0原文

我需要在Word中获得丰富的文本内容控制的“内容”,然后将该内容粘贴到另一个丰富的文本内容控制(格式)中。

这是我拥有的代码:

ActiveDocument.SelectContentControlsByTitle("original").Item(1).Range.FormattedText.Copy
ActiveDocument.SelectContentControlsByTitle("duplicate").Item(1).Range.Paste

哪个似乎可以使用,但是它将整个原始contentControl复制到(嵌套)重复的ContentControl ...而我只想单独使用格式的文本。

嵌套的原始和重复的内容

”在此处输入图像描述”

I need to get the 'contents' of a Rich Text Content Control in Word, and paste that content into another Rich Text Content Control (formatted).

Here's the code I have:

ActiveDocument.SelectContentControlsByTitle("original").Item(1).Range.FormattedText.Copy
ActiveDocument.SelectContentControlsByTitle("duplicate").Item(1).Range.Paste

Which seems to work, but it's copying the entire original ContentControl into (nested) the duplicate ContentControl... and I just want the formatted text alone.

original and duplicate content which is nested

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热风软妹 2025-02-16 07:34:43

尝试:

With ActiveDocument
  .SelectContentControlsByTitle("duplicate")(1).Range.FormattedText = _
  .SelectContentControlsByTitle("original")(1).Range.FormattedText
End With

Try:

With ActiveDocument
  .SelectContentControlsByTitle("duplicate")(1).Range.FormattedText = _
  .SelectContentControlsByTitle("original")(1).Range.FormattedText
End With
断爱 2025-02-16 07:34:43

与其使用VBA,不如映射内容控件。

对于丰富的文本控件,您需要映射XML零件。

数据映射

内容控制的真正力量在于它们的映射能力
(或绑定)到自定义XML数据存储嵌入在单词2007/2010中的数据存储
OfficeOpenxml格式文档文件。通过这种绑定:

  • 数据存储数据中的任何更改都会在映射到该数据的所有内容控件中自动重复。
  • 对映射的内容控件的任何更改都会自动更新数据存储和所有其他内容控件映射到该数据存储
    数据。

Word Content Controls Greg Maxey by Greg Maxey

,而您自己可以做这个?有许多免费工具可以为您做。

​它们具有不同的接口和功能,但所有这些都可以使您能够在文档中添加映射的内容控件,包括丰富的文本。

Rather than use vba for this, Map the Content Controls.

For Rich Text controls, you will need to map the XML parts.

Data Mapping

The real power of content controls lies in their ability to be mapped
(or bound) to a custom XML data store embedded in the Word 2007/2010
OfficeOpenXML format document file. Through this binding:

  • Any changes in the data store data is automatically repeated in all content controls mapped to that data.
  • Any changes to a mapped content control automatically updates the data store and all other content controls mapped to that data store
    data.

Word Content Controls by Greg Maxey

While you can do this yourself, why? There are a number of free tools that will do it for you.

I am sure there are more out there but I have used the above tools. They have different interfaces and powers but all of them give you the ability to add a Mapped Content Control to a document, including a Rich Text one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文