Here is some code that saves every worksheet in the active workbook. It is much more complex but is also more robust (better folder dialog, error checking, etc)
int count;
doc -cw; // Count the number of pages in project
if (count == 0) // Make sure there is at least one
{
// Output message and stop script
type "There are no workbooks in project.";
return;
}
string sPageName$ = page.name$; // Get the short name of the active page (window)
if (exist(%(page.name$), 2) != 2) // Make sure sure active page is a workbook.
{
// Output message and stop script
type "Current Window is not a workbook.";
return;
}
string sPath$;
dlgPath -sb path:=sPath title:="Choose a Folder" showfiles:=0; // This X-function is better than fdlog. It has more options if you are interested.
if (sPath.GetLength() == 0) // If user clicked Cancel button, sPath$ will be empty.
{
// Output message and stop script
type "Operation Cancelled";
return;
}
// User selected a folder, so continue script
for (int ii = 1; ii <= page.nlayers; ii++) // Loop through every layer (worksheet) in active page (workbook).
{
page.active = ii; // Activate layer (worksheet).
string sFile$ = "%(sPath$)\%(page.name$)%(layer.name$).txt"; // Create full path to the file name to save the worksheet.
// The "layer" variable is an object that represents the
// currently active layer (worksheet).
save -w %(layer.name$) "%(sFile$)"; // Save the worksheet into the file.
}
type "All worksheets in active workbook exported";
Note: If you are so inclined, the expASC X-function (http://www.originlab.com/doc/X-Function/ref/expASC) offers much more control over your data export than the save command.