Word session file name

Add-in Express™ Support Service
That's what is more important than anything else

Word session file name
 
Dave Campbell


Guest


I know I can use WordApp.ActiveDocument.Name to get the name of the "Active" document, but if I have, for example, 3 copies of Word up, and hence 3 copies of my Addin, is there any way I can tell from the Addin which document is associated with it? Obviously "ActiveDocument" is only associated with one of the three.

And obviously the doc associated with any session changes as files are opened/closed/etc.

Thanks!

-Dave
Posted 31 Jan, 2013 16:14:28 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Dave,

If you use Advanced TaskPanes panes, then you need to find the Word.Window the Hwnd property of which is equal to ADXWordTaskPane.CurrentWindowHandle and then get the document shown in that window using Window.Document.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Feb, 2013 03:14:45 Top
Dave Campbell


Guest


Thanks Andrei...

I'm not using the Advanced task panes unfortunately... but after I read your response, I realized I would still be up against the same issue... needing the Addin to know the document on it's own sort of like a push, rather than the user activating a control that polls. It's not the call that becomes the problem in this situation, but what launches that call in the 2nd or 3rd copy of Word that is not the active one.

After another time of staring at the monitor after reading your post, I may have a solution. If so, I'll blog it along with a bunch of other tips/tricks I've been saving up.

Thanks!

-Dave
Posted 01 Feb, 2013 10:09:54 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Dave,

It seems this can be solved by tracking opening/closing and activating documents.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Feb, 2013 01:30:33 Top
Dave Campbell


Guest


Hi Andrei...

Some of it has to do with the normal operation of Word, and to be honest, it works very nicely. It is frustrating though to have a document open, and 3 Addins on the page with no way for the Addin to know what that document is.

Opening/Closing gets fired just fine, but it's on the AddinModule, and there's no way to get from that to an instance of one of my addins. On a File Open, I actually have a way to get a message to my Addin, but only in a generic sense... I can tell any open instances that a document has been opened, but can't tell which Addin it's associated with... very frustrating.

Once the user makes an action on the Addin, it becomes easy because it is "ActiveDocument", but without that action, I'm stuck.

-Dave
Posted 04 Feb, 2013 09:58:35 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Dave,

I wonder what "3 Addins on a page" and "an instance of your add-in" could mean. Do you talk about a UserControl that you use as a Custom Task Pane?

JFYI, you can access AddinModule from whatever class within your add-in using this syntax:

MyProject.AddinModule.CurrentInstance.MyPropertyOrMethod

In particular, you can use the above syntax to connect to events provided by the Word events component.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Feb, 2013 10:11:37 Top
Dave Campbell


Guest


Sorry... wrong terminology.

3 TaskPanes in a Word instance... if there's 3 instances of Word up, then there are 3 instances of each of the TaskPanes.

My exact situation is this:

User selects a file under our control from an Addin in one of the Word instances.

Word either opens that document in that instance or another brand-new Word instance.

I'd like to be able to highlight the file they sel ected in the Addin, and sometimes because of the way Word works, that instance of Word ends up under the one that was there, and is not the 'Active document'.

I have a way that I can get my Addin to execute some code on a "Document Open", "Document Change", or "Document New", but if there's a way to get the document name in the inactive copy of Word fr om inside my Addin, I haven't found it.

Thanks!

-Dave
Posted 04 Feb, 2013 11:04:50 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Dave,

I assume that "Word instances" are actually Word windows opened in the same instance of WINWORD.EXE. If so, it means that opening a document might create a new Word window underneath the active window. Is this correct?

I'd scan the Windows collection (WordApp.Windows) in DocumentOpen and NewDocument and use Window.Hwnd to detect a new window. Then a simple Window.Document should produce the result.

Note that it is possible to open several windows for the same document, see View | New window in the Ribbon.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Feb, 2013 07:21:44 Top
Dave Campbell


Guest


Thanks Andrei...

I finally got this working by following your advice and changing to an ADXWordTaskPane.

A bit of an IQ test along the way, but was able to get the info squirted over to my taskpane, and get the highlighting working.

The only issue now is the fact that I can't float an ADXWordTaskPane, but they'll have to get over that... otherwise there's no way to show what's being edited.

Thanks a bunch!

-Dave
Posted 05 Feb, 2013 19:38:16 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Dave, you are most welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 06 Feb, 2013 01:09:20 Top