COM Add-in Word problem

T

Tom

I am able to sink the DocumentBeforeSave and DocumentChange but the Invoke
is not catching the DocumentOpen event.

I know that DocumentOpen is ID 4, DocumentBeforeSave is 8, and
DocumentChange is 3. Has anyone else experienced a problem with
DocumentOpen? Is this something with Office 2003? Or do I have to catch
the command button directly?

Thanks,
-Tom
 
V

Victor Heijke

I don't know what language you are using, but this is a walk through in
VS.Net 2003

Start a Shared Adin project (under Extensibility Projects)
Add a reference to Com: Microsoft Word 11.0 Object Model

In the code in Connect.vb
add under Imports
Imports Microsoft.Office.Interop

Change
dim applicationObject as Object
in
Dim WithEvents wordapp As Word.Application

Change in the OnConnction sub
applicationObject = application
in
wordapp = CType(application, Word.Application)

Add
Private Sub wordapp_DocumentOpen(ByVal Doc As
Microsoft.Office.Interop.Word.Document) Handles wordapp.DocumentOpen
MsgBox("Open")
End Sub

Change in the Project properties under Debugging the Start External Program
in the full path to winword.exe and start the project.

If you now open a document you will see the msgbox.

Victor Heijke
 
T

Tom

Hi Victor,

Thanks.... I figured out the problem. I was hoping to catch the open event
when the menu item was clicked, but instead it works after the menu item is
clicked and a document is selected. I am doing everything in C++ with ATL.
I have been trying to sink the menu item itself and I know I have the
commandbarbutton properly because I can disable it. Do you know if it's
possible to sink it or should I disable it and add my own menu items?

Thanks,
-Tom
 
V

Victor Heijke

If you are using DocumentBeforeSave than you are working on the actual
printing command. So if a user p.e. calls activedocument.printout in a macro,
than you're code is still working. If you just change the button not.
 
T

Tom

Thanks. So I can't catch the "Open..." menu item when it's clicked, only
after the fact with sinking DocumentOpen.

-Tom
 

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