Groups | Blog | Home
all groups > dotnet interop > february 2006 >

dotnet interop : Using Activator.GetObject with MS Word


Evan Stone
2/13/2006 4:41:05 PM
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
2/14/2006 12:15:06 PM
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?

[quoted text, click to view]

Thanks!

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


Cindy M -WordMVP-
2/15/2006 6:23:52 PM
Hi Evan,

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

[quoted text, click to view]

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 :-)
AddThis Social Bookmark Button