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

VulpesRank #55 · 29.2K reputationPosted Feb 7, 2013, 8:44 AM EST
xlApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, xlApp, new object[]{ "MacroName", Prefix, fName});
VulpesRank #55 · 29.2K reputationPosted Feb 7, 2013, 6:40 AM EST
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]});
}
}
richard smithRank #8,268 · 225 reputationPosted Feb 7, 2013, 7:04 AM EST
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?
VulpesRank #55 · 29.2K reputationPosted Feb 7, 2013, 7:45 AM EST
Shouldn't you just be invoking it the one time?
richard smithRank #8,268 · 225 reputationPosted Feb 7, 2013, 8:19 AM EST
Alpha123
Omega481
That is why I used a double for.
richard smithRank #8,268 · 225 reputationPosted Feb 7, 2013, 9:16 AM EST
VulpesRank #55 · 29.2K reputationPosted Feb 7, 2013, 9:26 AM EST
Was there an error message with the code as you originally had it (your opening post)?
richard smithRank #8,268 · 225 reputationPosted Feb 7, 2013, 9:29 AM EST