Visual Studio Tools for Office 2008 - 使用功能区按钮与活动文档交互

发布于 2024-07-13 12:22:22 字数 752 浏览 5 评论 0原文

我创建了自己的带有几个按钮的功能区工具栏选项卡。 我可以向我正在处理的文档添加文本和类似的操作。 现在我想添加一个按钮来保存我正在处理的文档,而不使用 Word 保存按钮,因为我想设置一些参数。

我发现的每个示例都展示了如何保存由我的代码启动的文档(Dim MyDoc As New Word.Application),但是当我从功能区按钮使用此类语法时 - ActiveDocument 表示没有活动文档。

有任何想法吗?

ThisAddIn.vb 包含:

Protected Overrides Function CreateRibbonExtensibilityObject() As  _
Microsoft.Office.Core.IRibbonExtensibility
    Return New MyRibbon()
End Function

MyRibbon.xml 非常基本(取自 MS 示例)

<group id="ContentGroup" label="Content">
    <button id="textButton" label="Insert Text"
        screentip="Text" onAction="OnTextButton"
        supertip="Inserts text at the cursor location."
    />
</group>

I've created my own ribbon toolbar tab with a few buttons. I can add text and similar actions to the document I'm working on. Now I want to add a button that will save the document I'm working on without using the Word save button because I want to set some of the parameters.

Every example I found showed how to save a document that was started by my code (Dim MyDoc As New Word.Application) but when I use such syntax from the ribbon button - ActiveDocument is saying that there is no active document.

Any ideas?

ThisAddIn.vb contains:

Protected Overrides Function CreateRibbonExtensibilityObject() As  _
Microsoft.Office.Core.IRibbonExtensibility
    Return New MyRibbon()
End Function

MyRibbon.xml is very basic (taken from an MS sample)

<group id="ContentGroup" label="Content">
    <button id="textButton" label="Insert Text"
        screentip="Text" onAction="OnTextButton"
        supertip="Inserts text at the cursor location."
    />
</group>

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

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

发布评论

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

评论(1

仅此而已 2024-07-20 12:22:22

您创建的新文档的类型不是 Word.Application。 您的功能区/加载项正在当前的 Word.Application 上下文中运行。

如果这确实是您正在做的事情,您应该创建 Word.Document 实例并保存它们。

您用来创建文档、功能区和保存更改的代码到底是什么?

The new document that you have created is not going to be of type Word.Application. Your ribbon/add-in is running in a current Word.Application context.

If this is indeed what you are doing, you should be creating instances of Word.Document, and saving those.

What exactly is the code you are using to create the document, the ribbon, and save your changes?

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