从 Excel 工作簿 VSTO 调用 Excel 加载项函数
我想在 Excel Add-In 2007 解决方案中创建一个方法,可以从我的 Excel Workbook 2007 解决方案中调用该方法。
我解释一下,我想从Excel工作簿2007解决方案的代码隐藏文件中调用Excel加载项的方法。我不想使用 VBA 宏。
请帮忙,提前致谢
谢谢, 姆纳尔·杰斯瓦尔
I want to create a Method in Excel Add-In 2007 solution which can be called from my Excel Workbook 2007 solution.
I explain, I want to call a method of Excel Add-In from code behind file of excel workbook 2007 solution. And I dont want to use VBA Macros.
Please help, thanks in advance
Thanks,
Mrinal Jaiswal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过大量谷歌搜索后,我现在可以自己回答了。
请按照以下步骤操作,
公共接口ICallMe
子我的函数()
End Interface
公共类 AddInUtilities
实现 ICallMe
End Class
5. 使用“注册 COM 互操作”选项构建您的加载项项目。要设置“Register for Com Interop”选项,请转到项目属性,然后转到“Compile”选项卡(在 VB.net 中),然后设置“Register for COM interop”进行检查。
现在,在您的 Excel 工作簿项目中,添加对此加载项的引用,并在工作簿的任何事件(例如单击按钮)上编写以下代码,
Dim addIn As Office.COMAddIn = Application.COMAddIns.Item("ImportData")
Dim utility As ImportData.ICallMe = TryCast(addIn.Object, ImportData .ICallMe)
utilities.MyFunction()
你已经完成了:)
唯一要记住的是不要从工作簿或工作表的启动事件中调用加载项函数。
我希望它对大家有所帮助,因为它对我有用。
谢谢,
姆纳尔·杰斯瓦尔
After doing much googleing i m able to answer it myself now.
Please follow the following steps,
Public Interface ICallMe
Sub MyFunction()
End Interface
Public Class AddInUtilities
Implements ICallMe
End Class
5.Build your add-in project with the Register for COM interop option. To set "Register for Com Interop" option, goto project property and then to "Compile" tab (In VB.net), and set the "Register for COM interop" to check.
Now in your excel workbook project, add the refrence to this add-in and on any event of your workbook like button click, write the following code,
Dim addIn As Office.COMAddIn = Application.COMAddIns.Item("ImportData")
Dim utilities As ImportData.ICallMe = TryCast(addIn.Object, ImportData.ICallMe)
utilities.MyFunction()
You are done :)
Only thing to remeber is that do not call the add-in function from startup event of your workbook or sheet.
I hope it helps you all, as it works for me.
Thanks,
Mrinal Jaiswal
非常感谢对我有用。现在已经为此苦苦挣扎了2天。
我想使用 Excel Addin(用户定义的函数)在 Office 2016 中动态创建一个新工作簿。
只是我如何使其工作的示例:
Thanks a lot that worked for me. Was struggling with it for 2 days now.
I wanted to create a new workbook on the fly in Office 2016 with my Excel Addin, user defined function.
Just a sample how I made it work :