.net - Opening Word Document through code in Visual Studio C# -
i developing office development visual studio. , receive error below
error: ** unable cast com object of type 'microsoft.office.interop.word.applicationclass' interface type 'microsoft.office.interop.word._application'. operation failed because queryinterface call on com component interface iid '{00020970-0000-0000-c000-000000000046}' failed due following error: no such interface supported (exception hresult: 0x80004002 (e_nointerface)). **
code: (also @ https://gist.github.com/1056809 )
if (file.exists((string)strdocpath)) { word.application wdapp = new word.application(); wdapp.visible = true; //error thrown here object readonly = false; object isvisible = true; object omissing = system.reflection.missing.value; //open word document //error thrown on line below. word.document adoc = wdapp.documents.open(ref strdocpath, ref omissing, ref readonly, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref isvisible, ref omissing, ref omissing, ref omissing, ref omissing); // activate document adoc.activate(); }
what error? how may avoid it?
try replacing first line after if statement this:
microsoft.office.interop.word.application wdapp = new microsoft.office.interop.word.application();
then make sure add reference "microsoft word 12.0 object library" com object, "microsoft.office.interop.word"in solution explorer.
i tested , blank ms word application came up. let's see if can far.
Comments
Post a Comment