简体   繁体   English

在Microsoft Access VBA中使用.Net DLL

[英]Using a .Net DLL in Microsoft Access VBA

Ok so I have an assembly, written in C#, using Visual Studio 2010. 好吧,我有一个用C#编写的程序集,使用Visual Studio 2010。

This Assembly contains one class, which contains one method which returns the word Result, the code is below: 这个程序集包含一个类,其中包含一个返回单词Result的方法,代码如下:

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: 属性窗口的“构建”选项卡中的输出部分如下所示:

Visual Studio输出窗口

When I click on Build, I get a DLL file and a TLB file. 当我单击Build时,我得到一个DLL文件和一个TLB文件。 I can add this TLB file to Microsoft Access simply by browsing to it. 我只需浏览它就可以将此TLB文件添加到Microsoft Access。

VBA参考窗口

Now, in Access I have a button and a label. 现在,在Access中我有一个按钮和一个标签。 I want to make the Caption property of my label equal to the result of testMethod. 我想让我的标签的Caption属性等于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

Thankyou 谢谢

Maybe next will work: 也许接下来会有效:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM