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
> Type wordType = Type.GetTypeFromProgID("Word.Application");
> Word.ApplicationClass app = null;
> app = Activator.GetObject(wordType, "[what goes here?]");
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 :-)