2012-01-13 100 views
7

好了,所以我有一個組件,用C#編寫,使用Visual Studio 2010在Microsoft Access VBA使用的.Net DLL

本屆大會包含一個類,它包含返回字結果一個方法,代碼低於:

using System.Runtime.InteropServices; 

namespace TestDLL 
{ 
    public class Class1 
    { 
     [ComVisible(true)] 
     public string TestMethod() 
     { 
      return "Result"; 
     } 
    } 
} 

在屬性窗口上構建標籤輸出部分看起來像這樣:

Visual Studio Output Window

當我CLIC k on Build,我得到一個DLL文件和一個TLB文件。我可以簡單地通過瀏覽它將此TLB文件添加到Microsoft Access。

VBA Reference Window

現在,在訪問我有一個按鈕和一個標籤。我想讓我的標籤的Caption屬性等於testMethod的結果。我想我需要做類似的東西下面,但我不知道,任何幫助將是非常讚賞:

Private Sub btnMain_Click() 

    Dim tm As TestDLL 
    Dim foo As String 

    foo = tm.testMethod 

    lblBarr.Caption = foo 

End Sub 

三江源

回答

8

也許下次會工作:

Private Sub btnMain_Click() 

    Dim tm As TestDLL.Class1 
    Dim foo As String 

    Set tm = New TestDLL.Class1 
    foo = tm.testMethod 

    lblBarr.Caption = foo 

End Sub 
+0

曾任職完美! – JMK 2012-01-13 13:53:38