Can not get active word object

F

fumade

hi Cindy
I cannot get active word instance,It throws exception message

Message = "Operation unavailable (Exception from HRESULT: 0x800401E3
(MK_E_UNAVAILABLE))"

But i can create a new word instance by
Application app = new ApplicationClass();
or
Type t = System.Type.GetTypeFromProgID("Word.Application", "localhost");
Application WordApplication =
(ApplicationClass)System.Activator.CreateInstance(t);


My code:
Type typWordApp = typeof(Application);
if (typWordApp != null)
{
try
{
WordApplication =
(ApplicationClass)Marshal.GetActiveObject
("Word.Application");
WordApplication.Visible = false;
}
catch(Exception e)
{
// EventLog.WriteEntry("TestWord",e.Message);
}

Can you give me some clues why this code does'nt work?

Thanks.
 

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