我需要使用VBA.Collection类,我需要注册一个COM组件才能做到这一点。我找到了VBA.dll并在visual studio项目中导入了这个dll。我正在创建一个类VBA.Collection的实例,但我在该行代码中得到一个异常:
VBA.Collection agentCollection = new VBA.Collection();
该例外有以下描述:
Retrieving the COM class factory for component with CLSID {A4C4671C-499F-101B-BB78-00AA00383CBB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
我在互联网上搜索了很多。例如,我看到以下链接:
2. Using VBA.Collection object in .NET
但我没有找到任何解决方案。请帮我 。我该如何解决这个错误?
I have seen this URL.我使用了接受答案的代码。但我收到此错误,“无法将MyCollection转换为ref VBA.collections”。
我试图通过这种语法注册VBA.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe VBA.dll
此命令的输出为:
Microsoft .NET Framework Assembly Registration Utility version 4.6.79.0
for Microsoft .NET Framework version 4.6.79.0
Copyright (C) Microsoft Corporation. All rights reserved.
Types registered successfully
我仍然收到此错误:
But when I try to run my project I am getting this error :
Retrieving the COM class factory for component with CLSID {A4C4671C-499F-101B-BB78-00AA00383CBB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
我不知道是什么原因。