Using Activator.GetObject with MS Word

E

Evan Stone

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
 
E

Evan Stone

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?]");

Thanks!

evan k. stone | software engineer
 
C

Cindy M -WordMVP-

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 :)
 

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