Calling c# dll from MS Excel vba code - Compile error: Method or data member not found
Calling c# dll from MS Excel vba code - Compile error: Method or data member not found
这是我生成 dll 的 c# 库,还在 属性 -> App,Build
中启用了 COM 可见性
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace howto_dll_for_excel
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("howto_dll_for_excel.CSharpTools")]
public class CSharpTools
{
[ComVisible(true)]
public string AddBrackets(string value)
{
return "[" + value + "]";
}
}
}
我正在尝试使用 vba 作为活动 X
在 MS excel 中访问此 dll
我在这个vba代码中添加了dll的引用,然后创建了一个按钮,这是宏定义
Sub Button1_Click()
Dim sheet As Worksheet
Dim tools As howto_dll_for_excel.CSharpTools
Dim value As String
Dim result As String
Set sheet = ActiveSheet
value = sheet.Cells(1, 1)
tools = CreateObject("howto_dll_for_excel.CSharpTools")
End Sub
我的问题是,
这里第一次访问项目howto_dll_for_excel自动列出CSharpToolsclass,
但是在最后的CreateObject语句中,它没有列出,即使我手动键入它也会提示错误
"Compile error: Method or data member not found"。
真正的问题是,dll 是 32 位的,excel 是 64 位版本
这是我生成 dll 的 c# 库,还在 属性 -> App,Build
中启用了 COM 可见性 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace howto_dll_for_excel
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("howto_dll_for_excel.CSharpTools")]
public class CSharpTools
{
[ComVisible(true)]
public string AddBrackets(string value)
{
return "[" + value + "]";
}
}
}
我正在尝试使用 vba 作为活动 X
在 MS excel 中访问此 dll我在这个vba代码中添加了dll的引用,然后创建了一个按钮,这是宏定义
Sub Button1_Click()
Dim sheet As Worksheet
Dim tools As howto_dll_for_excel.CSharpTools
Dim value As String
Dim result As String
Set sheet = ActiveSheet
value = sheet.Cells(1, 1)
tools = CreateObject("howto_dll_for_excel.CSharpTools")
End Sub
我的问题是,
这里第一次访问项目howto_dll_for_excel自动列出CSharpToolsclass,
但是在最后的CreateObject语句中,它没有列出,即使我手动键入它也会提示错误
"Compile error: Method or data member not found"。
真正的问题是,dll 是 32 位的,excel 是 64 位版本