好吧,我有一个程序集,用 C# 编写,使用 Visual Studio 2010。
这个Assembly包含一个类,其中包含一个返回单词Result的方法,代码如下:
using System.Runtime.InteropServices;
namespace TestDLL
{
public class Class1
{
[ComVisible(true)]
public string TestMethod()
{
return "Result";
}
}
}
属性窗口中“构建”选项卡中的输出部分如下所示:
当我点击构建时,我得到一个 DLL 文件和一个 TLB 文件。我可以通过浏览将此 TLB 文件添加到 Microsoft Access。
现在,在 Access 中我有一个按钮和一个标签。我想让我的标签的 Caption 属性等于 testMethod 的结果。我想我需要做类似于下面的事情,但我不确定,任何帮助将不胜感激:
Private Sub btnMain_Click()
Dim tm As TestDLL
Dim foo As String
foo = tm.testMethod
lblBarr.Caption = foo
End Sub
谢谢
最佳答案
也许下一个会起作用:
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
关于c# - 在 Microsoft Access VBA 中使用 .Net DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8849001/