If I use this sequence:
Comando: (vl-load-com)
Comando: (setq FulNam "C:\\Test\\TestFile.xls")
"C:\\Test\\TestFile.xls"
Comando: (setq *ExcelApp* (vlax-get-or-create-object "Excel.Application"))
#<VLA-OBJECT _Application 0017e524>
Comando: (setq *ActiveWbk* (vlax-invoke-method (vlax-get-property *ExcelApp*
'WorkBooks) 'Open FulNam))
#<VLA-OBJECT _Workbook 0017eb5c>
Comando: (vlax-invoke-method *ActiveWbk* 'Close :vlax-False)
:vlax-true
Comando: (vlax-invoke-method *ExcelApp* 'QUIT)
nil
The worbook is closed without prompts but Excel still running.
If I Open/New a drawing (sdi=1) Excel is closed.
---
If I use this function (with prompts) Excel is closed
correctly, why?
(defun MSX_Quit (ExlObj)
(or
(vlax-object-released-p ExlObj)
(progn
(or
(not *ActiveSht*)
(vlax-object-released-p *ActiveSht*)
(vlax-release-object *ActiveSht*)
)
(or
(not *ActiveWbk*)
(vlax-object-released-p *ActiveWbk*)
(progn
(vlax-invoke-method *ActiveWbk* 'Close)
(vlax-release-object *ActiveWbk*)
)
)
(vlax-invoke-method ExlObj 'QUIT)
(vlax-release-object ExlObj)
(setq *ExcelApp* nil *ActiveWbk* nil *ActiveSht* nil)
)
)
)
Or:
(defun MSX_Kill ( / ExlObj)
(while (setq ExlObj (vlax-get-object "Excel.Application"))
(MSX_Quit ExlObj)
(gc)(gc)
)
)
--
________________________________________________
Marc'Antonio Alessi (TV) Italy
(strcat "NOT a " (substr (ver) (if (= 15
(atoi (getvar "acadver"))) 8 5) 4) " guru.")
Excel = 2002
O.S. = XP Pro 2002 - Sp.1 - Ita
AutoCAD = 2002 Ita - Sp.1
_VERNUM = "K.0.44"
ACADVER = "15.06s (LMS Tech)"
(ver) = "Visual LISP 2000 (it)"
________________________________________________
A lisp program within AutoCAD should find out whether the external application
(here excel) is already running. If it is already running, then it should left
running after the lisp program executes. (Akin to saving system variables and
restoring them. The process of closure would also be well to include in the
local error handler.
Vlax-get-or-create.... short circuits the process by making sure that the
application is running regardless of whether it was already running prior to the
program call. This makes it difficult (but not impossible) to determine whether
to close the external application (here Excel). The external application should
only be closed if there are no other open documents (here workbooks). IOW
if the external application has documents other than the one managed by the
lisp application open, then it should remain open. In any case the external
worksheet and external workbook and external application should be
released. (Releasing the worksheet and workbook are less important
if you put them in local variables and do not refer to them again (I believe).
These are my perceptions only. I have do concrete information from the
program documentation to back them up.
HTH
Doug
"Marc'Antonio Alessi" <maalessi at tin dot it> wrote in message
news:BBA956BE733D66A0...@in.WebX.maYIadrTaRb...
> I need to close the "Excel.Application" without prompts
> to save or not.
>
> If I use this sequence:
>
<snip>
If you have a chance take a look at the book by Reinaldo Togores/Cesar Otero
about Programming in AutoCAD with Visual Lisp (is in Spanish - but the code
is universal), but has a chapter dedicated to excel with a full open source
code and covers all the aspects of Visual Lisp, here is the link, I have it
(but is not in my office now).
http://personales.unican.es/togoresr/
Luis Esquivel
But:
The importance of releasing external application objects is clear. The
cause
of the difference in your illustrations however is not necessarily as clear.
If the application is already in use (by the user of the computer), then it
should not be closed.
A lisp program within AutoCAD should find out whether the external
application
(here excel) is already running. If it is already running, then it should
left
running after the lisp program executes. (Akin to saving system variables
and
restoring them. The process of closure would also be well to include in the
local error handler.
Vlax-get-or-create.... short circuits the process by making sure that the
application is running regardless of whether it was already running prior to
the
program call. This makes it difficult (but not impossible) to determine
whether
to close the external application (here Excel).
> I have only one session of AutoCAD (SDI=1), no Excel running
The external application should
only be closed if there are no other open documents (here workbooks). IOW
if the external application has documents other than the one managed by the
lisp application open, then it should remain open. In any case the external
worksheet and external workbook and external application should be released.
> I have only the worbook I have just opened and closed
--
Questions:
1) why if I Open/New a drawing Excel is closed correctly?
2) why if I redo the same sequence (reopen the same workbook
without exit from the current drawing) Excel became instable?
3) why if I close Excel from inside Excel, the excel process in
task manager still running since I close AutoCAD or
Open/New a drawing?
Thanks again.
Marco
--
Spanish is similar to my "near Venice" dialect,
this summer I will be in Spain/Portugal and then
I need to learn some.
Cheers.
Marco
--
"Luis Esquivel" <www.caddximation.com> ha scritto nel messaggio
news:B39C4F3BA754482F...@in.WebX.maYIadrTaRb...
Some findings (after experimenting)
1. (vlax-invoke *excel* "quit") is ignored by the excel application has
another client besides the ACAD drawing session. Therefore it can
be called without worrying whether excel will close unexpectedly or
disastrously for the user.
If the current drawing is excel's only client, then
2. Excel will remain open until all of the following occur
a. It has been closed.
b. All objects have been released.
c. Explicit garbage collection is called (unknown reason - required
when objects within the application are created (workbooks, workbook, worksheet..))
or
3. Excel will remain open until the current drawing is closed AND
another is opened. Apparently Autocad cleans up after itself. The
garbage collection appears to occur when ACAD is setting up the
LISP environment for the next drawing. This happens in SDI=0
also.
or
4. Excel will remain open until the AutoCAD application is closed.
Apparently ACAD does a good job doing its own house cleaning.
Kudos to the ACAD programmers.
I am not sure how to answer your 3rd question.
Regards,
Doug
"Marc'Antonio Alessi" <maalessi at tin dot it> wrote in message news:FAC7ED1792A5F1EC...@in.WebX.maYIadrTaRb...
Cheers.
Marco
Correction:
1. (vlax-invoke *excel* "quit") is ignored IF the excel application has ..
Regards,
Doug
"Marc'Antonio Alessi" <maalessi at tin dot it> wrote in message news:EB70E1FCB78E3EB1...@in.WebX.maYIadrTaRb...