Excel SaveAs Overwrite message

I am writing a DXL script to export DOORS data to Excel. At the end, I am calling the Excel SaveAs function. If the file already exists, I get a message dialog "Do you want to overwrite this file ?", to which I always reply "Yes". Now, I want to execute the same script in batch mode. So how can I prevent getting this message ?
 

/*
 * This function saves the file as the passed in file name.(From ExcelFunctions.inc)
 */
bool saveFileAs(string filename) {
   if(fileOpen) {
      clear(args);
      put(args, "FileName", filename);
      
      if (excelVersion == "Excel.Application.12") {         // If Excel version is 2007
        put(args, "FileFormat", "56" );     // Save file as Excel 97-2003 .xls format
      }
        
      if(!checkResult(oleMethod(objWorkbook, "SaveAs", args))) {
         errorBox("File SaveAs failed.");
         return(false);
      }
      
      return(true);
   }
   
   errorBox("File not open");
   return(false);
}

sdauphin - Tue Aug 02 10:15:40 EDT 2011

Re: Excel SaveAs Overwrite message
OurGuest - Tue Aug 02 11:47:05 EDT 2011

Following shows all the args you will need to save.
ActiveDocument.SaveAs filename:="OLDFILE.docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

Re: Excel SaveAs Overwrite message
OurGuest - Tue Aug 02 13:02:31 EDT 2011

Pardon me. The previous saveas was for word.
for excel Try:

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
"P:\1-1\Book11.xls"

Application.DisplayAlerts = True

Re: Excel SaveAs Overwrite message
llandale - Tue Aug 02 13:29:33 EDT 2011

Don't know about your dialog problem from Excel; but I'd be tempted to just delete the file in DXL before commanding Excel to save it.
.... if (batchMode()) deleteFile(NameFile) // ignore no-such-file errors
This lets you respond to the prompt interactively but prevents the prompt in batchmode.

Your "errorBox" functions will likewise cause your DXL to stop in batchmode. That's actually a rather big problem. Perhaps this will work:

void  errorBox_Temp(string Message)
{            print "in 'errorBox_Temp()'\n"
   if (batchMode()) //
   then print Message "\n"
   else errorBox(Message)    // Call the standard "errorBox"
}  // end errorBox_Temp()
 
void errorBox(string Message)
{   // Override function of standard "errorBox"
             print "in overrride 'errorBox()'\n"
    errorBox_Temp(Message)
}   // end override errorBox()
errorBox("hello")  // debug


However, all "print" statements in batchMode will cause an additional command prompt window with all the prints, and when your batch program naturally stops, DOORS will linger until the next morning when you read the errors and close the window. So maybe instead of "print" you instead append to some error file.

Then there is "ack" and "confirm" and "query" and "infoBox" and "warningBox" bla bla bla. "confirm" and "query" can be overrided to always give the 1st response, and then your code has to be written such that the first response works well in batchmode.

Yup, its messy to have code that can run in batchMode and interactively.

 

 

  • Louie

 

 

Re: Excel SaveAs Overwrite message
David_G_Bond - Wed Aug 03 10:31:06 EDT 2011

llandale - Tue Aug 02 13:29:33 EDT 2011

Don't know about your dialog problem from Excel; but I'd be tempted to just delete the file in DXL before commanding Excel to save it.
.... if (batchMode()) deleteFile(NameFile) // ignore no-such-file errors
This lets you respond to the prompt interactively but prevents the prompt in batchmode.

Your "errorBox" functions will likewise cause your DXL to stop in batchmode. That's actually a rather big problem. Perhaps this will work:

void  errorBox_Temp(string Message)
{            print "in 'errorBox_Temp()'\n"
   if (batchMode()) //
   then print Message "\n"
   else errorBox(Message)    // Call the standard "errorBox"
}  // end errorBox_Temp()
 
void errorBox(string Message)
{   // Override function of standard "errorBox"
             print "in overrride 'errorBox()'\n"
    errorBox_Temp(Message)
}   // end override errorBox()
errorBox("hello")  // debug


However, all "print" statements in batchMode will cause an additional command prompt window with all the prints, and when your batch program naturally stops, DOORS will linger until the next morning when you read the errors and close the window. So maybe instead of "print" you instead append to some error file.

Then there is "ack" and "confirm" and "query" and "infoBox" and "warningBox" bla bla bla. "confirm" and "query" can be overrided to always give the 1st response, and then your code has to be written such that the first response works well in batchmode.

Yup, its messy to have code that can run in batchMode and interactively.

 

 

  • Louie

 

 

One method we have used to support both batch and interactive is to put the guts of the functionality into an include file and then have the interactive portion and batch portion in separate, much smaller, dxl files.

  • David Bond

Re: Excel SaveAs Overwrite message
llandale - Wed Aug 03 13:54:01 EDT 2011

David_G_Bond - Wed Aug 03 10:31:06 EDT 2011
One method we have used to support both batch and interactive is to put the guts of the functionality into an include file and then have the interactive portion and batch portion in separate, much smaller, dxl files.

  • David Bond

What I'm actually doing is coding the interactive DXL with the understanding that it can be run in BatchMode, Confirm and Query presume the 1st option and other stuff. The main BuildDialog() function will create the dialog and set its default values and 'realize' it; but then only 'show' it when not in batchmode and the callbacks don't use "show" nor "halt". Thus, the interactive DXL ends gracefully at the bottom of the file when in batchmode.

I then write a batchmode wrapper DXL associated with that DXL that "#include" the interactive part. I have special batch mode #include to override all the standard ack/warning/confirm bla bla bla such that the info is stored in a Buffer. The batch wrapper then finishes setting needed DBE values and calls the main interactive "OK" callback which runs the script. When finished, the special batch-mode messages in the buffer are dumped to a text file along with some other cleanup, and the batch wrapper ends. Executable code in the batch wrapper is a paltry 16 lines.

Since the main program generally displays a report, in the morning I see two reports, one from the main and the silly one from the batch wrapper, which generally just says "Done OK".

The Include line is pretty clever:
#include <../Project/Project-Scripts/DBAdmin/Archive_DataBase.dxl>
Which presumes that folder "Project" has a sibling folder defined in Addins, in my case folder "Module".

  • Louie