简体   繁体   English

如何从VS运行Excel宏?

[英]How to run Excel macros from VS?

如何从VS2010(C#)运行Excel宏?我使用Microsoft.Office.Interop.Excel命名空间

Try this article: 试试这篇文章:

http://support.microsoft.com/kb/306683 http://support.microsoft.com/kb/306683

The relevant part to run a macro is this (where oApp is the application instance in your code): 运行宏的相关部分是这样的(其中oApp是代码中的应用程序实例):

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

In addition to amarsuperstar's answer, 除了amarsuperstar的答案,

I'd like to state that you program needs to be a trusted source in order to call these macros. 我想声明您的程序需要成为可靠的来源才能调用这些宏。 And the Excel-File itself needs to be trusted as well. 并且Excel-File本身也需要被信任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM