Application.quit

Y

yuiriy

Why this code don't close excel? Code is assigned to button into userfor

Private Sub CommandButton4_Click(
ActiveWorkbook.Sav
If Workbooks.Count > 1 The
ActiveWorkbook.Clos
Els
Application.Qui
End I
End Su

TIA
 
T

Tom Ogilvy

You code would close the workbook with the code which causes the code to
terminate at that point.

Just do

for each bk in Application.Workbooks
bk.Save
Next
Application.Quit
 
Y

yuriy

Same result... In my primer I close book if there more books (there not .quit) , but when I us
application.quit not close this book... That I think that not a problem. Maybe userform


----- Tom Ogilvy wrote: ----

You code would close the workbook with the code which causes the code t
terminate at that point

Just d

for each bk in Application.Workbook
bk.Sav
Nex
Application.Qui
 
T

Tom Ogilvy

If excel can't close the workbook containing the code because the useform
prevents it, then you would need to unload the userform and run the code
from a general module, perhaps using Application.Ontime to start that
macro - to break the connection between the running code and the userform.

Public bCloseApp as Boolean

Public sub ShowForm
userform1.show
if bCloseApp then
for each bk in Application.Workbooks
bk.save
next
Application.Quit
End if
End Sub


in the userform

Private Sub CloseAppButton_Click()
bCloseApp = True
unload me
End Sub
 
Y

Yuriy

No success:( Is this working for you? On my PC with Excel 2003 not:(
Pls... Somebody to post working on Excel2003 code... When user close
form if only one workbook to close excel or if there other books to
close only activeworkbook...
Sample (not working):( All varianst in prevision post not working too
for me:(

-----
'Close form
Private Sub CommandButton4_Click()
Application.OnTime Now + TimeValue("00:00:02"), "closew"
Unload Me
End Sub


=====

Sub closew()

ActiveWorkbook.Save
If Workbooks.Count > 1 Then
ActiveWorkbook.Close
else
Application.Quit
endif

End Sub
 
Top