Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'"

由于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即可。

 

  1. Uninstall Microsoft Office
  2. Navigate to the Windows /assembly folder in the following location.
    Windows XP/2003 - C:/Windows/assembly
    Windows 2000 - C:/Winnt/assembly
  3. Locate Microsoft.Office.Interopt.Word Assembly.
  4. Right click on the file and choose Properties.
  5. Go to the Version tab.
  6. If the Value of the Product Name is 2007 Microsoft Office System, proceed to step # 9, otherwise skip to step # 10.
  7. Right click on the file and choose Uninstall.
  8. Locate Policy.11.Microsoft.Office.Interopt.Word Assembly.
  9. Right click on the file and choose Properties.
  10. If the Value of the Product Name is 2007 Microsoft Office System, proceed to step # 13, other skip to step # 14.
  11. Right click on the file and choose Uninstall.
  12. Reinstall Office 2003.

 

另:在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:
  1. Close ACT! and any Office applications
  2. Open the Add or Remove Programs control panel (Click Start, Control Panel, Add or Remove Programs).
  3. Uninstall Microsoft Office 2007 Primary Interop Assemblies
  4. Launch ACT! and test.

Method Two:
  1. Close all program.
  2. Launch Microsoft Office Word.
  3. Click on Help and select Detect and Repair.




  4. Check Restore my shortcuts while repairing option, then click Start. You may be prompted to insert the Microsoft Office Installation CD.
  5. Once the Detect and Repair is complete, close Microsoft Office Word.
  6. Right-click the Windows Start button, and then click Search (or Find) on the shortcut menu. A window opens.
    • Windows 95, 98, and NT 4.0:
      1. In the Find: All Files window, click the Name & Location tab.
      2. Enter normal.dot in the Named box.
      3. Click Local Hard Drives in the Look in drop-down list.
      4. Click Find Now.
    • Windows ME and 2000:
      1. In the Search Results window, enter normal.dot in the Search for files or folders named box.
      2. Click Local Hard Drives in the Look in drop-down list.
      3. Click Search Now.
    • Windows XP:
      1. In the Search Results window, enter normal.dot in the All or part of the file name box.
      2. Click Local Hard Drives in the Look in drop-down list.
      3. Expand More Advanced Options by clicking it.
      4. Select the Search system folders, Search hidden files and folders, and Search subfolders check boxes.
      5. Clear the Case sensitive and Search tape backup check boxes.
      6. Click Search Now.
    • Windows Vista:
      1. From the Start menu, right-click on Computer and choose Search
      2. When the Search screen comes up, type normal.dot in the Search box in the upper right.
      3. Check the box for Include non-indexed, hidden, and system files. Click Search.
    • Windows 7:
      1. Double click on the Computer icon.
      2. Type normal.dot in the Search box in the upper right.
  7. In the search results pane, right-click on each Normal.dot file, and then click Delete on the shortcut menu.
  8. Delete any Normal.dot and Normal.dotm files.
  9. Close the search results window.
  10. Launch Microsoft Word; this forces Word to recreate the Normal.dot file.
  11. Exit Word.
  12. Launch ACT!.

Method Three:
Use the following steps to uninstall Microsoft.Office.Interop.Word Assembly:
  1. Close all programs.
  2. Uninstall ACT! using the instructions in the Knowledgbase article that applies to your version from the list below:

    How to Uninstall ACT! by Sage 2007 (9.0) and ACT! by Sage Premium for Workgroups 2007 (9.0)
    Answer ID:19345

    How To Uninstall ACT! By Sage 2008 (10.0)
    Answer ID:21385

    How To Uninstall ACT! By Sage Premium 2008 (10.0) (EX Edition)
    Answer ID:21391

    How to Uninstall ACT! by Sage 2009 (11.0) and ACT! by Sage Premium 2009 (11.0)
    Answer ID:22952

    How to Uninstall ACT! by Sage 2010 and ACT! by Sage Premium 2010
    Answer ID:25185

    How to Uninstall Sage ACT! Pro 2011
    Answer ID:26765

    How to Uninstall Sage ACT! Premium 2011
    Answer ID:26989

  3. Navigate to the Windows /assembly folder in the following location.
    Windows XP/2003 - C:/Windows/assembly
    Windows 2000 - C:/Winnt/assembly
  4. Locate Microsoft.Office.Interopt.Word Assembly.
  5. Right click on the file and choose Properties.
  6. Go to the Version tab.
  7. If the Value of the Product Name is 2007 Microsoft Office System, proceed to step # 9, otherwise skip to step # 10.
  8. Right click on the file and choose Uninstall.
  9. Locate Policy.11.Microsoft.Office.Interopt.Word Assembly.
  10. Right click on the file and choose Properties.
  11. If the Value of the Product Name is 2007 Microsoft Office System, proceed to step # 13, other skip to step # 14.
  12. Right click on the file and choose Uninstall.
  13. Reinstall Office 2003.
  14. Reinstall ACT!
  15. Launch ACT! and test.
  16. Uninstall Microsoft Office

 


 

 

 

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了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值