c# - 在 Microsoft Access VBA 中使用 .Net DLL

标签 c# vba dll vb6 typelib

好吧,我有一个程序集,用 C# 编写,使用 Visual Studio 2010。

这个Assembly包含一个类,其中包含一个返回单词Result的方法,代码如下:

using System.Runtime.InteropServices;

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

属性窗口中“构建”选项卡中的输出部分如下所示:

Visual Studio Output Window

当我点击构建时,我得到一个 DLL 文件和一个 TLB 文件。我可以通过浏览将此 TLB 文件添加到 Microsoft Access。

VBA Reference Window

现在,在 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/

相关文章:

c# - 验证模拟方法使用也被模拟的特定 CancellationTokenSource

c# - 字符串替换换行符

excel - 通过 Excel VBA 运行 Shell 对象/命令时出错

excel - VBA 函数返回 0

c# - 无法调用服务,WCF 测试客户端?

c# - 是否可以只用C#编程模拟com口收发数据?

excel - 满足下一个空白单元格条件时中止宏

visual-studio-2008 - 应用程序无法启动:VS中的OpenCV x64编译使用x86库

c++ - 跨两个 DLL 的 `using` 语句

使用C编译DLL