How to handle menu events in addin ?

N

NinuX

I have developed an add-in for Word, using VB.NET abd I need to find out if
there is any way of handling events from Word's own menus ?

Basically I want to catch the File Save / Save As events so that I can save
a copy of the document to another location as well as / instead of where the
user chooses to save it
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TmludVg=?=,

In the Word environment, we use procedural names to intercept the built-in
commands. But for a COM Addin you need to use events. In this case,
DocumentBeforeSave.

An alternative would be to remove the commands from the Word interface and
replace them with your own (CommandBarButtons). Then you can do
Set dlg = Application.Dialogs(wdDialogFileSaveAs)
dlg.Display
and thus handle the actual save however you wish.

The Word dialogs have built-in arguments you can pick up. For example dlg.Name
will give you the filename the user selected. A list of arguments is available
in the Word object model Help files. Note that the arguments are old WordBasic
stuff and thus come through a late-binding interface. So things can get
awfully... frustrating if you have Option Explicit On. Better to insert a
separate "module" without that for the late-binding stuff if you have a lot of
it. Or get ready to build some wrapper functions.
I have developed an add-in for Word, using VB.NET abd I need to find out if
there is any way of handling events from Word's own menus ?

Basically I want to catch the File Save / Save As events so that I can save
a copy of the document to another location as well as / instead of where the
user chooses to save it

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
N

NinuX

thats very helpful, thanks for your help, Cindy


Cindy M -WordMVP- said:
Hi =?Utf-8?B?TmludVg=?=,

In the Word environment, we use procedural names to intercept the built-in
commands. But for a COM Addin you need to use events. In this case,
DocumentBeforeSave.

An alternative would be to remove the commands from the Word interface and
replace them with your own (CommandBarButtons). Then you can do
Set dlg = Application.Dialogs(wdDialogFileSaveAs)
dlg.Display
and thus handle the actual save however you wish.

The Word dialogs have built-in arguments you can pick up. For example dlg.Name
will give you the filename the user selected. A list of arguments is available
in the Word object model Help files. Note that the arguments are old WordBasic
stuff and thus come through a late-binding interface. So things can get
awfully... frustrating if you have Option Explicit On. Better to insert a
separate "module" without that for the late-binding stuff if you have a lot of
it. Or get ready to build some wrapper functions.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)


This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
N

NinuX

Hi Cindy,

My Office Add-in is written in VB.NET and I implement the
Extensibility.IDTExtensibility2 interface in my own Connect class

I did not understand how I can catch the "DocumentBeforeSave" event

I tried this ... Private WithEvents appWord As Word.Application
but it cannot find "Word.Application"

I have imported these ...

Imports Microsoft.Office.Core
Imports Extensibility
imports System.Runtime.InteropServices
Imports System.Windows.Forms

What am I doing wrong ?

Thanks
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TmludVg=?=,

Have you set a reference to the Word application libary and

Imports Word = Microsoft.Office.Interop.Word
My Office Add-in is written in VB.NET and I implement the
Extensibility.IDTExtensibility2 interface in my own Connect class

I did not understand how I can catch the "DocumentBeforeSave" event

I tried this ... Private WithEvents appWord As Word.Application
but it cannot find "Word.Application"

I have imported these ...

Imports Microsoft.Office.Core
Imports Extensibility
imports System.Runtime.InteropServices
Imports System.Windows.Forms

What am I doing wrong ?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top