本文介绍了COM& Excel / VBA中的后期绑定:ActiveX组件无法创建对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个.NET COM包装器,该包装器在VBA中用于在Excel中运行.NET程序集。



由于某些原因,我无法使用后期绑定从.NET COM dll中创建对象。

  Set obj = CreateObject( COMwrapper.MyClass)

引发

但是,如果我执行此操作,


  • 使用早期绑定并引用COMwrapper.tlb

  • 以管理员权限运行Excel



COMwrapper .NET项目及其依赖项.NET DLL是使用Visual Studio构建的2019已提升为管理员模式,以便它可以在构建过程中注册COMwrapper。



我也尝试使用VS作为普通用户来构建解决方案,而无需注册COM包装器。稍后手动运行具有管理员权限的regasm.exe。但这是相同的结果。



如果我使用RegDllView.exe窥视注册表,请


I have built a .NET COM wrapper which I use in VBA to run a .NET assembly in Excel.

For some reason I can't use late-binding to create objects from the .NET COM dll.

Set obj = CreateObject("COMwrapper.MyClass")

This throws

It works however if I:

  • Use early-binding and reference the COMwrapper.tlb
  • Run Excel with admin rights

The COMwrapper .NET project and it's dependencies .NET DLLs are built with Visual Studio 2019 elevated to admin mode, so that it can register the COMwrapper in the build process.

I have also tried to build the solution with VS as normal user, without registering the COM wrapper. Later manually I have run regasm.exe with admin rights. But it has been the same result.

If I peek into the registry with RegDllView.exe (https://www.nirsoft.net/utils/registered_dll_view.html), the COMwrapper DLL seems to be registered and with the right path.

This is how I have set up the COM part

The class file

namespace COMwrapper
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("904EBB3C-7A28-490E-B2E5-0CC0C66E907A")]
    public class MyClass : IMyClass

The interface file

namespace COMwrapper
{
    [Guid("540D119F-6676-4CE9-B763-50F4F2976E1E")]
    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IMyClass

This has previously worked fine! If I distribute the DLLs to another computer and register the wrapper, it works fine with late binding.

解决方案

Not an answer, just supporting my comment. I created a DLL in Admin rights on VS2019, and was able to access via both early and late binding. This is how i set it up

这篇关于COM& Excel / VBA中的后期绑定:ActiveX组件无法创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 04:47