Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How to make Excel 2007 quit automatically

Hi
This

If Workbooks.Count < 1 Then Application.Quit


works in Excel 2003 but Excel 2007 tries to restart.
Is there something else I should try ?


TIA

Andrew
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to make Excel 2007 quit automatically

You can try this to close and save the workbook and
if it is the only file that is open close Excel

Dim wb As Workbook
Dim I As Integer

For Each wb In Application.Workbooks
If wb.Windows(1).Visible Then I = I + 1
Next wb
If I = 1 Then
Application.Quit
ThisWorkbook.Close SaveChanges:=True
Else
ThisWorkbook.Close SaveChanges:=True
End If

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Andrew Bourke" wrote in message ...
Hi
This

If Workbooks.Count < 1 Then Application.Quit


works in Excel 2003 but Excel 2007 tries to restart.
Is there something else I should try ?


TIA

Andrew

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How to make Excel 2007 quit automatically

Thanks for your reply Ron.

The CloseOff macro I am trying to fix works fine in Excel 2003 (I need
it to work in both Excel 2003 and Excel 2007).

This is the code I have been using and when it runs in Excel 2007,
a window pops up saying Excel has stopped working, its looking for a
solution to the problem, and then , Excel is re-starting, and it restarts.

Inserting the line

ThisWorkbook.Close SaveChanges:=True

causes an error saying:
"This workbook is currently being referenced by another workbook and
cannot be closed", even after the other workbook has been closed.


'--- CLOSE NO SAVE - quit if this is the only book open
If AA.Caller = "Quit3" Then
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
If Workbooks.Count < 1 Then
AA.DisplayAlerts = False
ThisWorkbook.Close SaveChanges:=True
AA.Quit
End If
Exit Sub
End If

Any other ideas would be appreciated.
Thank you
Andrew Bourke














On 26/01/2009 11:52 PM, Ron de Bruin wrote:
ThisWorkbook.Close SaveChanges:=True


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to make Excel 2007 quit automatically

Now I know your problem

See this page (bottom part :Code run from a shape can crash Excel 2007)
http://www.rondebruin.nl/shape.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Andrew Bourke" wrote in message ...
Thanks for your reply Ron.

The CloseOff macro I am trying to fix works fine in Excel 2003 (I need
it to work in both Excel 2003 and Excel 2007).

This is the code I have been using and when it runs in Excel 2007,
a window pops up saying Excel has stopped working, its looking for a
solution to the problem, and then , Excel is re-starting, and it restarts.

Inserting the line

ThisWorkbook.Close SaveChanges:=True

causes an error saying:
"This workbook is currently being referenced by another workbook and
cannot be closed", even after the other workbook has been closed.


'--- CLOSE NO SAVE - quit if this is the only book open
If AA.Caller = "Quit3" Then
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
If Workbooks.Count < 1 Then
AA.DisplayAlerts = False
ThisWorkbook.Close SaveChanges:=True
AA.Quit
End If
Exit Sub
End If

Any other ideas would be appreciated.
Thank you
Andrew Bourke














On 26/01/2009 11:52 PM, Ron de Bruin wrote:
ThisWorkbook.Close SaveChanges:=True


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How to make Excel 2007 quit automatically

Thanks for your help Ron.
I took your advice and inserted forms buttons and now it works properly.

On 27/01/2009 7:16 AM, Ron de Bruin wrote:
Now I know your problem

See this page (bottom part :Code run from a shape can crash Excel 2007)
http://www.rondebruin.nl/shape.htm




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007- can't get it to automatically make backups JoeZ Excel Discussion (Misc queries) 1 March 17th 10 01:19 PM
make excel automatically add a decimal Darrell Eddy Excel Worksheet Functions 1 March 20th 08 05:32 PM
Why do my formulas quit functioning in Excel 2007? cyndiwise notsowise Excel Worksheet Functions 2 December 10th 07 01:04 PM
Application.Quit in Excel 2007 Paul D.[_2_] Excel Programming 4 June 1st 07 05:49 AM
vba advice how 2get a input box to quit by entering the word quit+ 4 a msgbox to disp RELWOD85[_4_] Excel Programming 3 August 1st 05 07:11 PM


All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"