尝试从VBA调用.NET函数 - 在VBA中使用RUN [英] Trying to call a .NET function from VBA - using RUN in VBA

查看:270
本文介绍了尝试从VBA调用.NET函数 - 在VBA中使用RUN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.Net类库,并已经完成了将其包含在excel中所需的全部内容。 (显示为COM可见,对于互联网和regasm的dll)
我使用excel 2007.在excel加载项,我看到我的TestLib.Functions作为检查。我可以访问我的VBA代码中的函数:

  Set lib = New TestLib.Functions 
returnVal = lib.Add(5);

这工作正常。



对于其他代码审查原因,我还看到使用RUN方法访问的另一个库的一些功能:

 运行(avSomeFunction,paramvalue)

VBA编辑器,如果我尝试以相同的方式访问添加功能,

 运行(添加,5 )

我收到一条错误,指出找不到名称为Add的宏。是否必须,我应该
再次添加tlb作为参考再次VB编辑工具 - 引用再次,除了Regasm为.net dll?有人可以让我知道这里有什么问题。



p.s:因为一些非常疯狂的原因,我刚刚这样工作一下子,但是再次失败了。非常奇怪:(

解决方案

区别之间:添加一个tlb作为使用'Run'的引用函数VS的参考有答案,基本上,我在VBA项目中缺少对tlb的引用,除了注册dll之外,tlb还需要添加作为参考。


I have a .Net class library and have done all things needed to include it in excel. (expoting as COM visible, for com-interop and regasm'ing the dll as well) I use excel 2007. In the excel addins, I see my 'TestLib.Functions' as checked. I am able to access the function in my VBA code as :

Set lib = New TestLib.Functions
returnVal = lib.Add(5);

This works fine.

For other code review reasons, I also saw some functions from another library accessed using the RUN method as :

Run("avSomeFunction", paramvalue)

Now, in the VBA editor, if I try to access the 'Add' function in the same way,

Run("Add", 5)

I get an error saying 'Cannot find a macro with name Add'. Is it neccesary that I should add tlb as a reference once again in the VB editot-tools-references again, apart from doing Regasm for the .net dll? Can someone please let me know what is the problem here.

p.s : for some very crazy reason, I just had this working once suddenly but again failed to work there after. very weird:(

解决方案

Difference between : adding a tlb as reference to invoke function VS using 'Run'? has the answer to this. Basically, I was missing the reference to the tlb in the VBA project. Apart from registering the dll, the tlb also needs to be added as a reference.

这篇关于尝试从VBA调用.NET函数 - 在VBA中使用RUN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆