Eli Blokh
Eli Blokh

Reputation: 12293

How to run Excel macros from VS?

How to run Excel macros from VS2010(C#)?I use Microsoft.Office.Interop.Excel namespace

Upvotes: 6

Views: 4340

Answers (2)

Falcon
Falcon

Reputation: 3160

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.

Upvotes: 1

amarsuperstar
amarsuperstar

Reputation: 1783

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);
}

Upvotes: 8

Related Questions