从.NET应用程序运行VBA code [英] run vba code from .net applications

查看:203
本文介绍了从.NET应用程序运行VBA code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的金额code VBA编写的,我需要迁移到.NET应用程序。

I have a very large amount of code written in VBA that I need to migrate to a .Net application.

这是不切合实际的改写这一切,因为实在太多了,所以我在想,如果有一种方法从.NET调用这些VBA函数

It isn't practical to rewrite all of it as there is just too much, so I was wondering if there is a way to call these vba functions from .NET

感谢。

更新:

我一直在调查这些和事实证明,他们是不恰当的。该应用程序不是Microsoft Office和不公开任何形式的运行微距功能。

I've been investigating these and it turns out they aren't appropriate. The application isn't Microsoft Office and doesn't expose any sort of "Run" macro functionality.

做完我们遗留的第三方应用程序,并通过样品的记事本应用程序生成的文件进行比较,文件格式(在记事本中查看)看起来很相似(相同的前几个字符,总体布局是一样的),所以我不知道是否有可能是个方法,使用这个项目加载/保存功能来访问宏。

Having done a comparison of the files produced by our legacy third party application and by the sample notepad application, the file formats (viewed in notepad) look very similar (same first few characters, general layout is the same), so I was wondering if there was perhaps a way to use this project load/save functionality to access the macros.

我已经做了一些基本的测试,尝试只加载我们现有的VBA到记事本VBA不起作用。我猜我需要更新应用程序的界面,但是,不幸的是这似乎是不可能得到一个VBA许可协议了,因为微软已经决定每个人都应该使用VSTA而不是 - 所以我不知道的最好的方法继续与此有关。

I've done some basic tests, attempting to just load our existing vba into the notepad vba doesn't work. I'm guessing I need to update the application's interface, however, unfortunately it seems it isn't possible to get a VBA license agreement anymore as Microsoft have decided everyone should be using VSTA instead - so i'm not sure of the best way to proceed with this.

假设有没有一种方法,VBA集成到我们的新的应用我唯一剩下的想法是创造一种被称为在的Application_Start或periodic_execute入口点的遗留应用程序中的新的VBA函数,而这些都可以设置了所需的全局变量和调用等功能,但我仍然希望的东西更好。

Assuming there isn't a way to integrate VBA into our new application my only remaining idea is to create a new VBA function in the legacy application which is called on the application_start or periodic_execute entry points, and have these be able to set up the required global variables and call other functions, however I'm still hoping for something nicer.

任何想法表示欢迎! :)

Any ideas welcome! :)

推荐答案

我假设在这里,您的VBA code包含在的Microsoft Office应用程序之一。

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

所有的Microsoft Office应用程序暴露Application.Run()方法,它接受 宏或子过程的名称。宏或Sub过程必须声明为public。

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.

您可以使用的.Net code创建相关的Office应用程序(如Word,Excel等)的实例,然后调用Run方法,传递宏/程序的名称作为调用宏或Sub过程字符串参数,例如

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")

Run方法也接受了一些参数,可以包含你需要提供给宏或过程的任何参数的值。

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.

MSDN文章,包含了一些例子

这篇关于从.NET应用程序运行VBA code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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