run vba code from .net applications

拜拜、爱过 提交于 2019-12-06 11:10:58

I am assuming here that your VBA code is contained in one of the Microsoft Office applications.

All the Microsoft Office applications expose the Application.Run() method which accepts the name of a macro or sub procedure. The macro or sub procedure must be declared Public.

You can use .Net code to create an instance of the relevant Office application (Word, Excel, etc.) and then invoke the macro or Sub procedure by calling the Run method, passing the macro/procedure name as a string argument e.g.

objWordApp.Run("MyVBAMacro")

The Run method also accepts a number of arguments which can contain the values of any parameters you need to supply to the macro or procedure.

This MSDN article contains some examples.

Maybe you can try to convert the code into VSTO. Some posts about this are found here:

http://blogs.officezealot.com/hansen/archive/2007/01/10/20048.aspx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!