COM & Late binding in Excel/VBA: ActiveX component can't create object

二次信任 提交于 2020-03-05 04:04:31

问题


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

Error 429: ActiveX component can't create object

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.


回答1:


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



来源:https://stackoverflow.com/questions/60319593/com-late-binding-in-excel-vba-activex-component-cant-create-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!