Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Activator.GetObject with MS Word

137 views
Skip to first unread message

Evan Stone

unread,
Feb 13, 2006, 7:41:05 PM2/13/06
to
Hi,

What I'd like to do is attach to an instance of Word (if it's running), and
if it's not running then create a new instance of the application. To that
end, I was wondering if the following was a valid use of the
Activator.GetObject() method:

public Word.ApplicationClass CreateWordApplicationInstance()
{

Type wordType = Type.GetTypeFromProgID("Word.Application");
Word.ApplicationClass app = null;

try
{
app = Activator.GetObject(wordType, "");
}
catch(Exception rex)
{
app = new Word.ApplicationClass();
}

return app;

}

Thanks!

evan k. stone | software engineer
----------------------------------------
santa rosa, ca, usa


Evan Stone

unread,
Feb 14, 2006, 3:15:06 PM2/14/06
to
OK... How about this question: If I was going to try to get a running
instance of MS Word with Activator.GetObject, what should go into the URL
parameter of the GetObject method?

> Type wordType = Type.GetTypeFromProgID("Word.Application");
> Word.ApplicationClass app = null;

> app = Activator.GetObject(wordType, "[what goes here?]");

Cindy M -WordMVP-

unread,
Feb 15, 2006, 12:23:52 PM2/15/06
to
Hi Evan,

I've never encountered "Activator". But I have successfully used
Word.Application wdApp = (Word.Application)
System.Runtime:InteropServices.Marshal.GetActiveObject("Word.Application");

> OK... How about this question: If I was going to try to get a running
> instance of MS Word with Activator.GetObject, what should go into the URL
> parameter of the GetObject method?
>
> > Type wordType = Type.GetTypeFromProgID("Word.Application");
> > Word.ApplicationClass app = null;
> > app = Activator.GetObject(wordType, "[what goes here?]");
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

0 new messages