由于Visula studio 2010 的VSTO 只支持office2010和2007,所以若想通过VSTO操作office 2003组件,须另辟途径。
引起此错误的主要原因,是当前正在使用office2003,但曾经装过office2007 或 office2010,并且引用了office2003的互操作COM组件。因为装过2007或2010,导致对应的office assembly都被识别为较高版本的office assembly(2007或2010),而无法正常引用当前在用的office assembly(2003),从而导致错误。
解决方法:彻底写在office2007或2010,并且卸载对应的assembly。方法如下(务必用windows 自带的资源管理器进入目录,才能得到整个列表):
进入C:/WINDOWS/assembly,卸载所有版本号为非11.0.0.0的office相关的assembly(也即其属性中版本页面内的软件名称不是office 2003的相关assembly)及找到Policy.11.Microsoft.Office.Interopt.Word ,若其属性中版本页面内的软件名称不是office 2003,则也对应卸载之。
全部处理完成后,重装office2003即可。
另:在c#对office进行互操作时,要注意引用的是.net 组件还是COM组件。
COM组件: microsoft word 11 library, microsoft office 11 library... 等
asp.net为: microsoft.office.interop.excel ...
COM office 2003组件
选择COM里面选择Microft Office 12.0 object Library和Microft Excel 11.0 object
Library分别点确定即可!同样如果要引用World选Microft World 11.0 object Library!
对于多版本组件有相同GUID问题,基本是因为在引用的时候,同类组件所引用的版本不一致所致。去掉相关的同类引用,并重新添加引用应该就可以解决问题。
source: click here
Error: "Object reference not set to an instance of an object" or "Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'" When Attempting to Write Letter or Send E-mail | |
Question | |
You are attempting to write a new letter using Microsoft Word as the processor and you receive the following error: Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)). You may also receive an "Object Reference Not Set To An Instance of an Object" error message when attempting to send E-Mail from within Sage ACT! using Microsoft Office Outlook® 2003. |
|
Answer | |
This issue has been known to occur if you are using Microsoft Office 2003 (version 11), and Microsoft Office 2007 (version 12) was previously installed on the computer and Microsoft.Office.Interop.Word Assembly is still associated with Office 2007. Note: The following information is provided as a convenience. Sage not provide support for Microsoft Products. For more information on this topic, please visit Microsoft.com. Method One:
Method Two:
Method Three: Use the following steps to uninstall Microsoft.Office.Interop.Word Assembly:
|
|
First off, some basic background info. This problem arose for me after uninstalling Office 2007 and going back to Office 2003 due to the Office 2007 PIA's not being able to communicate correctly and provide backwards compatibility with Office 2003. Upon reinstallation none of my COM calls to any Office COM DLL would work, every call would return the error that is mentioned in the post i.e. CANTLOADLIBRARY, with a long CLSID number e.g. {A5EDEDF4-2BBC-45F3-822B-E60C278A1A79}. I deduced that this must have been due to Office 2007 leaving a bad trail of uninstalled registry key entries...
This CLSID is the key to solving the problem.
First off copy the CLSID from the error window that appears in VB.NET. Access the registry via Start, Run, Cmd, RegEdt32, enter. Once the registry editor loads up, do a search (ctrl F3) on that specific CLSID (I didn't include the braces, but it shouldn't matter). The registry should find a key located under the HKEY_CLASSES_ROOT -> CLSID subkey. Expand this key and you should see 3 nodes: ProxyStubCLSID,ProxyStubCLSID32 and the important one - TypeLib. Essentially what is happening is that when you make the COM call to a specific Office assembly. The assembly opens up the registry and finds this key which gives it the CLSID of the TypeLib it must call in order to initiate a call to the COM.
Under the TypeLib key copy the (Default) Entry (It should be another long CSLID key). Now the easiest way to find this new key entry relating to the CLSID, is to go back up to the root key, HKEY_CLASSES_ROOT and look for the TypeLib subkey. I did this by simply pushing "T" on the keyboard till I got to the all the "T's" on the level below the HKEY root. Once you find this key, highlight the key and do a search (Ctrl F3) from this key for the TypeLib CLSID that you copied earlier. Once you find it, expand it and see if there are multiple versions of the typelib i.e. 8.3, 8.4, 8.5. You want to eliminate the the later versions that are pointing to non-existant TypeLib's. To do this, expand the Version key (ie. 8.3), then expand the "0" key, then the win32 key and check the value of the default entry. This value should be a file path. Mine was pointing to a tlb file in an Office12 directory (Office 2007), that obviously didn't exist since I uninstalled 2007. Simply delete this key, and now when the COM interface attempts to locate the latest TypeLib it will find one that does indeed exist, and will hopefully run error free.
or reinstall office 2003
另:
source: click here
在添加word模板时突然遇到一个问题:库没有注册 (异常来自异常来自 HRESULT:0x80029C4A (TYPE_E_CANTLOADLIBRARY )在网上搜了半天没效果,就试着去老外的网页上瞅瞅,没想到还真找到了,下面是解决方法:
找到这个路径:C:"Program Files"Common Files"Microsoft Shared"VSTO"8.0"Microsoft Visual Studio 2005 Tools for Office Runtime (找对应VS版本即可)
它下面有一个 install.exe 运行之 o了