Help: Open events and document creator

D

Diego

Hi,

First of all, I am new with VSTO, so sorry for my unknowledge...

I have created an Office add-in (for Word & Excel) using Visual Studio 2005,
with C# (Extensibility - Shared Add-in.)

I have the created code, with the 'Connect' class:
public class Connect : Object, Extensibility.IDTExtensibility2

and I have the add in launch event in 'OnConnection()' method

I have 2 problems:

1. I need a 'opened document' event every time a word or excel document is
open. I have seen code samples to handle these events with methods like
private void ThisDocument_Startup(object sender, System.EventArgs e)
where 'ThisDocument' is the class name. But with my 'Connect' class it does
not work. I am really confussed, could anyone tell me what to do?

2. Every time a new document is open, I must get the creator, how can I
get the current document? Is it possible to do it in a generic way? I mean,
for excel & word documents.

I am not asking for the complete solution, just some steps to get my targets.

Thanks a lot in advance

Diego
 
P

Philip Chan

Well, IDTExtensibility2::OnConnection has 4 parameters, the first one
Application is you need.

Use "As" statment convert Application to
Microsoft.Office.Interop.Word.ApplicationClass, then you have add your
delegate to ApplicationClass.ApplicationEvents2_Event_DocumentOpen event

the delete declare is :

public delegate void ApplicationEvents2_DocumentOpenEventHandler(
[In] Document Doc
);

so you get the current document.

ApplicationClass.ActiveDocument can get the current document too.
 
D

Diego

Thanks a lot for your response, I have what I need!! :)

I have only a problem, since I have my code (and so my addin) only for Word,
using "Microsoft.Office.Interop.Word.ApplicationClass",...

I need the addin working also for Excel (and maybe for Powerpoint), is it
possible to use a "common" code? I hope you understand me...

What I need is to get the active 'office document' event, and to retrieve
the creation user and date (OK from Word). I suppose it is common for all
office documents...

Thanks again,

Diego
 
P

Philip Chan

I know how to do this via C++.

In C++, you can get the IConnectionContainer interface from Application via
IUnkown::QueryInterface, and then query the IConnectionContainer whether it
support some connection point. If if does, then connection it.

Well, I doesn't find a IConnectionContainer in VSTO document, may be you
should use "is" statement to tell which application it is running.
 

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