Can't instantiate a COM object written in C# from VBA (VB6 ok)

后端 未结 5 2014
小鲜肉
小鲜肉 2020-12-08 23:41

Using VS 2008, here is my COM object

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Wi         


        
5条回答
  •  天命终不由人
    2020-12-08 23:57

    RC1, I tested this with your code from VBScript and from within Office 2007's Excel, everything works fine.

    Since your able to create the COM object from within a VB6 form we should assume that your .net framework is ok. Can you rule out issues with VBA? Can you create a .vbs file and put this in it:

    Dim o As Object  
    Set o = CreateObject("Test9.COMINT")  
    o.Init "A", "B"
    

    Save the file and double click it. If you get an error, then I would think there is an issue with it being registered, if you don't get an error, then I would look at Office and VBA and see if something is missing or not installed properly.

    Another option is to add a reference to COM object and use early binding? I think you might need to export a typelibrary first, but you should be able to add a reference and simple new the object up.

提交回复
热议问题