How to customize save behaviour in Word using VSTO

浪子不回头ぞ 提交于 2019-12-20 03:53:22

问题


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!

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

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.

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.


回答1:


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

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

Office integration (Word) - intercepting save
Handle File->New in Word 2007



来源:https://stackoverflow.com/questions/1887368/how-to-customize-save-behaviour-in-word-using-vsto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!