Dear Raoul,
1) no it is not possible to close an Excel file from within Stata.
2) You can launch an external program with the -shell- command, but
technically this is not "from within Stata".
Here you google something like: kill process windows (or whatever OS
you are using) and find a plethora of utilities for the purpose:
http://www.tech-recipes.com/rx/446/xp_kill_windows_process_command_line_taskkill/
describes the standard command taskkill.
Type in the OS command line : taskkill /? for help
3) I would not recommend this way of programming though. Perhaps your
program could try to delete the file, if it fails, ask the user to
close Excel, or automatically fallback to a different name if
interaction is to be avoided. E.g. report_0001.xls if report.xls is
opened.
Best regards,
Sergiy Radyakin
On Wed, Nov 11, 2009 at 6:54 AM, raoul reulen <[email protected]> wrote:
> In a do-file I write the final results of my analyses to an excel
> file, but the do-file will (obviously) not run when the excel file
> with the results is open as it cannot overwrite the excel file because
> it is in use. Is there an easy way to close the excel file from within
> Stata? Perhaps using the shell command?
>
> Thanks.
>
> Raoul
> -------------------------------------------------------
> Raoul C. Reulen
> Cancer Research UK Training Fellow
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/