这是我从中生成dll的c#库,也启用了Property中的COM visiblity - > App,Build
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会自动列出CSharpTools类,
但是在最后一个CreateObject语句中,它没有列出,即使我手动输入它提示错误
“编译错误:找不到方法或数据成员” .
1 回答
真正的问题是,dll是32位,excel是64位版本