在Microsoft Access VBA中使用.Net DLL [英] Using a .Net DLL in Microsoft Access VBA
问题描述
好的,所以我有一个使用Visual Studio 2010用C#编写的程序集.
Ok so I have an assembly, written in C#, using Visual Studio 2010.
此程序集包含一个类,该类包含一个返回Result字的方法,代码如下:
This Assembly contains one class, which contains one method which returns the word Result, the code is below:
using System.Runtime.InteropServices;
namespace TestDLL
{
public class Class1
{
[ComVisible(true)]
public string TestMethod()
{
return "Result";
}
}
}
属性窗口的构建"选项卡中的输出部分如下所示:
The output section in the Build tab on the properties window looks like so:
当我单击Build时,我得到一个DLL文件和一个TLB文件.我只需浏览即可将其添加到Microsoft Access.
When I click on Build, I get a DLL file and a TLB file. I can add this TLB file to Microsoft Access simply by browsing to it.
现在,在Access中,我有一个按钮和一个标签.我想使我的标签的Caption属性等于testMethod的结果.我在想我需要做以下类似的事情,但是我不确定,任何帮助将不胜感激:
Now, in Access I have a button and a label. I want to make the Caption property of my label equal to the result of testMethod. I'm thinking I need to do something similar to below but I'm not sure, any help would be much appreciated:
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
这篇关于在Microsoft Access VBA中使用.Net DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!