在C#中运行VBA宏 [英] Running VBA macros in C#

查看:374
本文介绍了在C#中运行VBA宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI

我一直在很多地方寻找答案,但是我总是能得到答复,但是不幸的是,这并不是很有帮助.

I've been looking for an answer in a lot of places, but I always get the response, and unfortunately this is not very helpful.

我想做的是从Excel C#加载项运行用VBA编写的宏(在Excel中的工作簿,工作表或模块中).

What i would like to do is to run macros written in VBA (in a workbook, or worksheet, or module in excel) from an Excel C# add-in.

我去过这里http://support.microsoft.com/kb/306683/zh-cn,我使用过RunMacro方法:

I've been here http://support.microsoft.com/kb/306683/en-us and i have user the method RunMacro:

private void RunMacro(object oApp, object[] oRunArgs)
{
oApp.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);
}

仅当宏是在Excel中的模块中编写时,此方法才能正常工作.如果宏是写在工作簿或工作表中的,则它只是找不到指定的宏.

This works just fine only if the macro is written in a module in Excel; If the macro is written in a workbook or a worksheet, then it just cannot find the specified macro.

我想做的是运行在工作簿和工作表中编写的宏,而不是在模块中编写的宏.

What i would like to be able to do is run macros that are written in workbooks and worksheets apart from those in the modules.

可以做到吗?我想它可以,我只是不知道如何....期待解决方案.

Can this be done? I guess it can, i just don't know how....Looking forward to a solution.

推荐答案

与MS Office相关问题使用 Microsoft Office for Developers论坛 . 用于Office的Visual Studio工具 论坛或 Office讨论组.

For MS Office related questions use the Microsoft Office for Developers Forums .
For office related questions use the Visual Studio Tools for Office forum or Office Discussion Groups.

自VS 2010发布以来,最近几周来,支持Office的论坛一直在变化.

The forums that support Office have been going under changes in recent weeks, since the release of VS 2010.


这篇关于在C#中运行VBA宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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