Capturing Word Events in a VB.Net Add In

D

Daryl

Hi,

I'm trying to write a shared add in for Word 2003 using VB.Net where I want
to override the default behaviour for opening and saving so that documents
can be downloaded and uploaded from a central repository. I'm not sure about
how to set up the add in to do this. Do I need to somehow attach the add in
to the DocumentOpen and DocumentBeforeSave events, or can I try to capture
the button clicks for opening and saving documents?

Does anyone have any sample code that shows me how to do this?

Thanks,

Daryl.
 
A

Andrei Smolin [Add-in Express]

Daryl,

I'd add two custom command bar buttons (Open from Repository and Save to
Repository), connect to the Save, Save As, Save All, etc built-in command
bar buttons (you can find their IDs with our free Built-in Controls
Scanner - http://www.add-in-express.com/downloads/controls-scanner.php) and
intercept corresponding keyboard shortcuts. In the event handlers of the
custom buttons above, I'd show appropriate dialogs. In the events of the
built-in controls, I'd recognize if the document should be saved to
Repository and execute a respective routine.

To add a custom button to the Standard command bar, use the Application
object supplied in the StartupComplete event to create a button (CType may
be required):
Dim WithEvents myControl as Office.CommandBarButton =
wordApplication.CommandBars("Standard").Controls.Add(msoControlButton).
Then set other command bar button properties (Caption, ShortcutText, Style,
State, BeginGroup, Visible) and handle the Click event of myControl.

You have to handle the scenario when the button has already been added to
the command bar. When switching to another document, you have to create (or
connect to) the button anew. Be aware, the button may become disconnected
all of a sudden. That is, you should be ready to re-connect it. You should
also take care of your command bars and buttons not being shown in Outlook
e-mail inspectors when Word is set as the default mail editor. To handle
keyboard shortcuts, you have to do some Win32 API programming. In addition,
if you use PIAs, you can support the only Word version. To make your add-in
trusted in Office, you have to sign its starting-point DLL with a strong
key. It isn't possible if you use the Shared Add-in wizard in VS: shared
add-in has MSCOREE.DLL as its starting-point DLL.

All this stuff is included in Add-in Express that provides version-neutral
PIAs (http://www.add-in-express.com/docs/net-tips.php#What are PIAs), an
add-in loader of its own
(http://www.add-in-express.com/docs/net-deploying-addins.php), as well as
command bar, command bar control and keyboard shortcut components
(http://www.add-in-express.com/docs/net-components.php)

To handle events of a document, connect to it in an appropriate event of
Word.Application object. To determine if the BeforeDocumentSave event is
invoked by some user actions or by Word's AutoSave feature, see the
"BeforeDocumentSave Event" topic in this newsgroup.

Hope this helps.

Regards from Belarus,

Andrei Smolin
Add-in Express Team Leader
www.add-in-express.com
 
D

Daryl

Thanks very much Andrei,

That has helped me onto the right track. I will have a look at Add-in
Express before I do too much more.
 

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