我试图在我创建的C#dll中使用VBA中的方法。该文件是COM可见的,并在我的VBA文件中引用。
这是我的VBA代码:
Private Declare Function COMPaste Lib "C:\Blah\bin\x86\Debug\TestCOMExposure.dll" Alias "Countdown" (ByVal left As Integer) As Integer
Sub TestA()
Dim instance As TestCOMExposure.TestProgram
Set instance = New TestCOMExposure.TestProgram
MsgBox (instance.COMPaste)
End Sub
在C#dll中查看我的方法:
namespace TestCOMExposure
{
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(
System.Runtime.InteropServices.ClassInterfaceType.None)]
[ProgId("TestCOMExposure.TestProgram")]
[Guid("4EFE27BF-A442-4F93-9A55-A00BD2D7160A")]
public class TestProgram : ITestProgram
{
public void Countdown()
{
int i = 60;
int day = 3;
int left = i - day;
Console.WriteLine("Saba has {0} days left", left);
Console.Read();
}
我的界面代码:
[System.Runtime.InteropServices.ComVisible(true)]
[Guid("20DF3D06-0DC6-445D-9149-F23A34B0624F")]
public interface ITestProgram
{
void Countdown();
}
运行VBA代码时出现的错误是“自动化错误系统无法找到指定的文件。请让我知道我做错了什么。