Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Quit Excel if ONLY Workbook Open else Close Excel instead

I currently use:

Sub Button14_Click()
Application.DisplayAlerts = Fasle
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub

Is there a way for Excel to Check if ANY other Workbooks are Open or Not.
If NO others are Opened, then to QUIT rather than to CLOSE ???

But if there is another Workbook open then Excel simply Closes this Workbook
an NOT Quitting Excel.


Can you do this?

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Quit Excel if ONLY Workbook Open else Close Excel instead

Corey,
You can check the Workbooks collection, allowing for the WB that contains
this code and the possibility of hidden workbooks, notably Personal.xls.
something based on:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim WB As Workbook

For Each WB In Application.Workbooks
Debug.Print WB.Name
If WB.Name < ThisWorkbook.Name Then
If WB.Windows(1).Visible = True Then Exit Sub
End If
Next

Application.Quit

End Sub

NickHK

"Corey" wrote in message
...
I currently use:

Sub Button14_Click()
Application.DisplayAlerts = Fasle
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub

Is there a way for Excel to Check if ANY other Workbooks are Open or Not.
If NO others are Opened, then to QUIT rather than to CLOSE ???

But if there is another Workbook open then Excel simply Closes this

Workbook
an NOT Quitting Excel.


Can you do this?

Corey....




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Quit Excel if ONLY Workbook Open else Close Excel instead

Thank You Nick.
Perfectly done..


"NickHK" wrote in message
...
Corey,
You can check the Workbooks collection, allowing for the WB that contains
this code and the possibility of hidden workbooks, notably Personal.xls.
something based on:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim WB As Workbook

For Each WB In Application.Workbooks
Debug.Print WB.Name
If WB.Name < ThisWorkbook.Name Then
If WB.Windows(1).Visible = True Then Exit Sub
End If
Next

Application.Quit

End Sub

NickHK

"Corey" wrote in message
...
I currently use:

Sub Button14_Click()
Application.DisplayAlerts = Fasle
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub

Is there a way for Excel to Check if ANY other Workbooks are Open or Not.
If NO others are Opened, then to QUIT rather than to CLOSE ???

But if there is another Workbook open then Excel simply Closes this

Workbook
an NOT Quitting Excel.


Can you do this?

Corey....






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
Open workbook on close Mike[_114_] Excel Programming 0 January 8th 07 10:24 PM
my password quit working in an excel workbook, help! Cheryl B Excel Worksheet Functions 0 April 26th 06 01:04 PM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
Close Open Woorkbook and Quit Excel Lucy[_2_] Excel Programming 5 December 24th 03 02:52 PM
EXCEL.exe stays open after Quit method in an HTA myriams9 Excel Programming 5 December 4th 03 07:06 AM


All times are GMT +1. The time now is 10:00 AM.

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"