如何使用VSTO在Word中自定义保存行为 [英] How to customize save behaviour in Word using VSTO

查看:173
本文介绍了如何使用VSTO在Word中自定义保存行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何使钻头协同工作的基本问题:在搜索4小时之前和之后,我还没有使用VSTO,所以我决定询问!

Fundamental question on how to get the bits to work together: I've not used VSTO before and after 4 hrs of searching I've decided to ask!

我想为该单词创建一个简单的AddIn,当用户保存任何文档时将执行该单词。

I want to create a simple AddIn for word that will execute when the user saves ANY document.

认为我所要做的就是将在VisualStudio 2008中创建一个AddIn,并将我的代码放入ThisAddIn类中

I thought all I would need to do would be to create an AddIn in VisualStudio 2008, and put my code in the ThisAddIn class


 Public WithEvents objWordApp As Word.Application

    Private Sub objWordApp_DocumentBeforeSave(ByVal Doc As Word.Document, ByVal SaveAsUI As Boolean, ByVal Cancel As Boolean)
        MsgBox("my addin code is running")
    End Sub

就是这样。只有这永远不会运行。

and that would be that. Only this never gets run.

这里有一个线索 http://msdn.microsoft.com/zh-cn/library/bb221264.aspx 我没有声明该对象,但是我不知道这是否是我丢失了,或者如果丢失了,该声明代码将到达哪里。

There is a clue here http://msdn.microsoft.com/en-us/library/bb221264.aspx that I have failed to declare the object, but I have no idea if this is what I am missing, or if it is, where that declaration code would go.

推荐答案

这是 BeforeSave的VSTO特定事件处理程序。 (带有示例): MSDN

Here is the VSTO specific event handler for "BeforeSave" (with example): MSDN

如果要完全覆盖File> Save word的行为,请参考以下Stackoverflow问题:

If you want to completely override the File > Save behavior of word, please reference these Stackoverflow questions:

Office集成(Word)-拦截保存

处理文件-> Word 2007中的新功能

这篇关于如何使用VSTO在Word中自定义保存行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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