问题
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