Activate a Word document loaded from within the add-in...

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

Activate a Word document loaded from within the add-in...
 
Heinz-Josef Bomanns




Posts: 206
Joined: 2008-02-28
Hi,

Word 2007 or 2010 starts up with an empty document. By a click on a ribbon button our WinForms dialog is invoked and shown modal with '.ShowDialog'. On some point the user can open a document choosen from a list within the dialog. We do this with 'Documents.Open' and the document loads fine. The problem is that it is not activated resp. not shown in the window behind our dialog, it stays minimzed in the taskbar and 'ActiveDocument' still references the first empty document. Tried something like 'currDoc = Documents.Open, currDoc.Activate' but that doesn't work. Any ideas anybody how to get the document activated behind our dialog? Thanks for any hints...
__________________
Greetings, HJB
Posted 11 May, 2012 04:30:15 Top
Eugene Astafiev


Guest


Hi Heinz-Josef,

May I see the code you use for opening documents in Word? I am interested in the parameters list you pass to the Open method of the Documents class from the Word Object Model.

BTW Could you please specify the build number of Add-in Express you have currently installed on the PC?
Posted 11 May, 2012 05:02:29 Top
Heinz-Josef Bomanns




Posts: 206
Joined: 2008-02-28
Hi Eugene,

Build is 6.6.3059 - before posting any questions i always make sure latest version is used and all available Service Packs and Hotfixes for Office are installed.

I don't have any special parameters, it's just a

gobjWord.Documents.Open(strFilename)


where 'gobjWord' is a global variable set to 'Me.HostApp' in the AddInModule and 'strFilename' points to an existing document in Word's default document directory...
__________________
Greetings, HJB
Posted 12 May, 2012 00:56:08 Top
Eugene Astafiev


Guest


Hi Heinz-Josef,

First of all, please note that you don't release underlying COM object properly. The Documents property of the Aplication class in Word returns an instance of the Documents collection which should be released after. You can read more about this in the http://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/ article on our technical blog.

Also the http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.documents.open.aspx method of the Documents class accepts a lot of parameters. Among them is the visible parameter which has the following description:

True if the document is opened in a visible window.


Please try to play with the parameters list. May be one of them will do the trick.
Posted 14 May, 2012 03:45:15 Top