The code below is a bit of an improvement. It allows you to either go through every worksheet in the whole project or only those in a selected folder in Project Explorer (except that it will NOT go into subfolders if this method is chosen).
If you look in the code there will be two "doc" commands, one of which is commented out. You can change which one is commented out to change the behavior according to your wishes.
string strName$; // String to hold name of new book
newbook result:= strName$; // Create new workbook putting it's name into strName$
range rngNewCol1 = [%(strName$)]Sheet1!col(1); // Get column 1 of newly created workbook, sheet 1
range rngNewCol2 = [%(strName$)]Sheet1!col(2); // Get column 2 of newly created workbook, sheet 1
int jj = 1; // Counter for adding rows to columns in new workbook
// !!! The following command loops over every worksheet in the whole project
doc -e LB {
// !!! The following command loops over every worksheet in a selected folder in Project Explorer. Does NOT look in subfolders
//doc -ef LB {
if (exist(%H, 2) == 0) // Not a workbook, must be a matrix
{
continue;
}
if (%H == strName$) // Skip newly created workbook
{
continue;
}
range rngX = col(1); // The current worksheet X column
// Loop over all Y columns in current worksheet
for(int ii = 2 ; ii <= wks.ncols; ii++)
{
range rngY = col($(ii)); // The current worksheet Y column
limit rngY; // Puts some stats into tree LIMIT
rngNewCol1[jj] = rngX[limit.imax]; // Get X of row with maximum. Put into column 1 of newly created workbook
rngNewCol2[jj] = rngY[limit.imax]; // Get Y of row with maximum. Put into column 2 of newly created workbook
jj++; // Increment jj counter for adding rows to columns
}
}