tags:

views:

412

answers:

2

How to pass an array from C# function to VBA?

Can it be done?

+1  A: 

You need to create a COM object in C#, and then reference that COM object like you would any other COM object in VB.

Tutorial here: http://www.codeproject.com/KB/COM/com_object_in_c_.aspx

Robert Harvey
A: 

Has anyone found out how to do this?

My c# code reads,

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

And I want to call this by passing an array of strings as the parameter. So it would be something like,

RunMacro(wordApp, new Object[] { "InsertStrs", strArr}); 

// where InsertStrs is the name of the macro and strArr is the array of strings

My Word/VBA macro should look like,

Sub InsertStr(strArr() As String) // not sure about this

Help would be great.

Zorrin