How can I add a usercontrol to a word document?

Hi

I am working with a Word Document project using VS2008 Beta 2 and VSTO. All of the documents I am working with are based on a template I created and have a custom ribbon. I can add a usercontrol to a document using the syntax:

Globals.ThisDocument.Controls.AddControl(control, range, width, height, controlName)

If I have multiple Word documents open and want to activate a specific one, I can loop through them using the syntax:

'-

Dim WordAppAs Microsoft.Office.Interop.Word.Application

WordApp =CType(System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"), Word.Application)

Dim wordDocAs Word.Document

ForEach wordDocIn WordApp.Documents

If wordDoc.Name = desiredDocNameThen

wordDoc.Activate()

EndIf

Next

'-

However, once I activate a document using the above syntax, I cannot add a usercontrol to it because the Word.Document object does not have a controls collection. So If I could add a usercontrol using the syntax

Globals.ThisDocument.Controls.AddControl(control, range, width, height, controlName)

then how could I accomplish the same thing with the wordDoc example above. If this is not possible, is it possible to loop through the open documents a different way? Thanks.

[2186 byte] By [RomanBenko] at [2008-2-26]
# 1

I'm going to move this message to the VSTO Orcas forum, as you're more likely to get assistance from someone who's actually using that version.

My guess would be that you need to first CType the document to a Tools.Document (you'll have to workout the exact type name). But you want to be careful to not try this with a document that does not have the VSTO customization attached to it. You can only add controls to documents that already have the runtime customization.

CindyMeister at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Visual Studio Tools for Office Orcas...

Visual Studio Orcas

Site Classified