Communicating between C# and VBA

前端 未结 3 1423
长发绾君心
长发绾君心 2021-01-05 02:12

At the request of my boss I created a small set of scripts that are used to periodically monitor the status of certain devices and processes. This info is subsequently proce

3条回答
  •  悲&欢浪女
    2021-01-05 03:03

    You can use a .NET DLL with your VB6 project and create an instance of any object you have defined in your assembly. This is done by registering the .NET assembly (.dll) for COM interop (use in VB6) by creating a type library file (.tlb). The .tlb file contain extra information so that your VB6 project can use your .dll. Note, your VB6 project will not reference the .dll but the corresponding .tlb file. You can use the Regasm.exe utility to generate and register a type library and register the location of the managed assembly. Then its just a matter of creating an instance of your .NET object, whether it be a WinForm or some other cool class. =).

    Dim MyDotNetObject As MyDotNetClass
    
    Set MyDotNetObject = New MyDotNetClass
    MyDotNetObject.SomeMethod(value1, value2)
    
    ''end of execution
    Set MyDotNetObject = Nothing
    

    See: http://support.microsoft.com/default.aspx?scid=kb;en-us;817248

提交回复
热议问题