tags:

views:

249

answers:

1

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  A: 

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

Mike Regan
Those combined with http://msdn.microsoft.com/en-us/library/cc442981.aspx have got me going. Thanks Mike.
Andiih