从MS Excel vba代码调用c#dll - 编译错误:找不到方法或数据成员 [英] Calling c# dll from MS Excel vba code - Compile error: Method or data member not found
问题描述
这是我生成dll的c#库,同时启用了属性 - > App,Build
This is my c# library I from which dll is generated, Also have enabled the COM visiblity in Property -> 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 + "]";
}
}
}
我正在尝试访问dll在MS excel中使用vba作为活动X
I am trying to access this dll in MS excel using vba as active X
我添加了dll的引用到这个vba代码,然后创建了一个按钮,这是宏定义
I added the reference of the dll to this vba code,then created a button and this is the macro definition
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类,
Here the first access of the project howto_dll_for_excel automatically lists the CSharpTools class,
但是在最后一个CreateObject语句中,它没有列出,即使我手动输入它提示错误
but in the last CreateObject Statement ,it is not listing,even if I type it manually prompts error
编译错误:找不到方法或数据成员。
"Compile error: Method or data member not found" .
推荐答案
真正的问题是,dll是32位,excel是64位版本
The real problem was that, the dll was 32 bit and the excel was 64 bit version
这篇关于从MS Excel vba代码调用c#dll - 编译错误:找不到方法或数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!