简体   繁体   中英

How to run Excel macros from VS?

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

Try this article:

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

The relevant part to run a macro is this (where oApp is the application instance in your code):

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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