I have a C# array set-up like this:
Prefix = new string[2] { "Alpha", "Omega" };
fName = new string[2] { "123", "481" };
for (int i = 0; 0 < Prefix.Length; i++)
{
for (int x = 0; 0 < fName.Length; x++;
{
xlApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, xlApp, new object[], { "MacroName", Prefix, fName }
}
}
The problem I have is that Excel continues to cycle the elements in the array, and does not terminate the array once all elements have been processed. Is this a C# issue, or an issue in my Excel Macro?
Loading
VulpesPosted Feb 7, 2013, 1:44 PM
xlApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, xlApp, new object[]{ "MacroName", Prefix, fName});
richard smithPosted Feb 7, 2013, 2:29 PM
VulpesPosted Feb 7, 2013, 2:26 PM
Was there an error message with the code as you originally had it (your opening post)?
richard smithPosted Feb 7, 2013, 2:16 PM
richard smithPosted Feb 7, 2013, 1:19 PM
Alpha123
Omega481
That is why I used a double for.
VulpesPosted Feb 7, 2013, 12:45 PM
Shouldn't you just be invoking it the one time?
richard smithPosted Feb 7, 2013, 12:04 PM
Public Sub MacroName(Prefix, fName)
Call TestingProcedure(Prefix, fName)
End Sub
When I change my C# code to your suggestion I get a byRef type mismatch on the variables I try to pass?
VulpesPosted Feb 7, 2013, 11:40 AM
for (int i = 0; 0 < Prefix.Length; i++)
{
for (int x = 0; 0 < fName.Length; x++;
{
xlApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, xlApp, new object[]{ "MacroName", Prefix[i], fName[x]});
}
}