Difference between : adding a tlb as reference to invoke function VS using 'Run'?

后端 未结 1 1428
暗喜
暗喜 2021-01-27 21:37

Assume I have a .Net library with a class(TestClass) with a function \'Add\'. I am accessing this in Excel by writing a VBA addin. I want to know the difference between the foll

相关标签:
1条回答
  • 2021-01-27 22:07

    You need to replace the = with the As keyword for the Dim statement in your code snippet. This works (assuming that the class is registered properly with COM):

    Sub AccessExternalUdf()
        Dim obj As New MyNamespace.MyClass
        result1 = obj.MyMethod    
        result2 = Run("MyMethod")
    End Sub
    

    The difference (as stated above by @Hans) is early versus late (Run) binding.

    0 讨论(0)
提交回复
热议问题