Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Check for other open wokbooks

I was using the line below at the end of my code and all was well. Until
someone had other Excel workbooks open (besides the one I had created) and
the code ran doing what it was supposed to do and closed excel completely. I
do want the Excel to close down, but only if my workbook is the only
workbook open.

So is there any way to amend what I have to check for other open workbooks,
and if there are any open the just close my workbook only?



Application.Quit

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Check for other open wokbooks

On Apr 28, 10:30*pm, "ordnance1" wrote:
I was using the line below at the end of my code and all was well. Until
someone had other Excel workbooks open (besides the one I had created) and
the code ran doing what it was supposed to do and closed excel completely.. I
do want the Excel to close down, but only if my workbook is the only
workbook open.

So is there any way to amend what I have to check for other open workbooks,
and if there are any open the just close my workbook only?

Application.Quit


Try
Application.ActiveWorkbook.Close(SaveChanges:=Fals e)
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Check for other open workbooks

Thanks.

That will close the active workbook but I need to close Excel only if there
are no other workbooks open.

"Suri" wrote in message
...
On Apr 28, 10:30 pm, "ordnance1" wrote:
I was using the line below at the end of my code and all was well. Until
someone had other Excel workbooks open (besides the one I had created)
and
the code ran doing what it was supposed to do and closed excel
completely. I
do want the Excel to close down, but only if my workbook is the only
workbook open.

So is there any way to amend what I have to check for other open
workbooks,
and if there are any open the just close my workbook only?

Application.Quit


Try
Application.ActiveWorkbook.Close(SaveChanges:=Fals e)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Check for other open workbooks

Application.Workbooks.Count

If more than 1 then close current WB only

If only 1 then close WB and Application.Quit


Gord Dibben MS Excel MVP

On Wed, 28 Apr 2010 14:57:10 -0700, "ordnance1"
wrote:

Thanks.

That will close the active workbook but I need to close Excel only if there
are no other workbooks open.

"Suri" wrote in message
...
On Apr 28, 10:30 pm, "ordnance1" wrote:
I was using the line below at the end of my code and all was well. Until
someone had other Excel workbooks open (besides the one I had created)
and
the code ran doing what it was supposed to do and closed excel
completely. I
do want the Excel to close down, but only if my workbook is the only
workbook open.

So is there any way to amend what I have to check for other open
workbooks,
and if there are any open the just close my workbook only?

Application.Quit


Try
Application.ActiveWorkbook.Close(SaveChanges:=Fals e)


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Check for other open workbooks

Thanks

here is my test code based on your reply: But I get an Invalid use of
Property error and it highlights .Count

Sub test()

Application.Workbooks.Count

If Application.Workbooks.Count = 0 Then

Application.Quit
End

End If

ThisWorkbook.Close False

End Sub

"Gord Dibben" <gorddibbATshawDOTca wrote in message
...
Application.Workbooks.Count

If more than 1 then close current WB only

If only 1 then close WB and Application.Quit


Gord Dibben MS Excel MVP

On Wed, 28 Apr 2010 14:57:10 -0700, "ordnance1"
wrote:

Thanks.

That will close the active workbook but I need to close Excel only if
there
are no other workbooks open.

"Suri" wrote in message
...
On Apr 28, 10:30 pm, "ordnance1" wrote:
I was using the line below at the end of my code and all was well.
Until
someone had other Excel workbooks open (besides the one I had created)
and
the code ran doing what it was supposed to do and closed excel
completely. I
do want the Excel to close down, but only if my workbook is the only
workbook open.

So is there any way to amend what I have to check for other open
workbooks,
and if there are any open the just close my workbook only?

Application.Quit

Try
Application.ActiveWorkbook.Close(SaveChanges:=Fals e)




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Check for other open workbooks

Option Explicit
Sub test()

If Application.Workbooks.Count = 1 Then
'save this workbook with the code
'ThisWorkbook.Save
'or
'or just lie to excel so the user doesn't get a prompt!
ThisWorkbook.Saved = True

'no matter what, quit excel
Application.Quit 'which closes the workbook, too.
End If

End Sub

=========
I don't know what you're doing, but I've never understood how a developer could
guess whether an open workbook should be saved when it's closed.

Either choice could cause a catastrophe -- closing the file without saving may
lose hours of work and saving the file could mean that the test changes that
should have been discarded are now there in place of the real data!



ordnance1 wrote:

Thanks

here is my test code based on your reply: But I get an Invalid use of
Property error and it highlights .Count

Sub test()

Application.Workbooks.Count

If Application.Workbooks.Count = 0 Then

Application.Quit
End

End If

ThisWorkbook.Close False

End Sub

"Gord Dibben" <gorddibbATshawDOTca wrote in message
...
Application.Workbooks.Count

If more than 1 then close current WB only

If only 1 then close WB and Application.Quit


Gord Dibben MS Excel MVP

On Wed, 28 Apr 2010 14:57:10 -0700, "ordnance1"
wrote:

Thanks.

That will close the active workbook but I need to close Excel only if
there
are no other workbooks open.

"Suri" wrote in message
...
On Apr 28, 10:30 pm, "ordnance1" wrote:
I was using the line below at the end of my code and all was well.
Until
someone had other Excel workbooks open (besides the one I had created)
and
the code ran doing what it was supposed to do and closed excel
completely. I
do want the Excel to close down, but only if my workbook is the only
workbook open.

So is there any way to amend what I have to check for other open
workbooks,
and if there are any open the just close my workbook only?

Application.Quit

Try
Application.ActiveWorkbook.Close(SaveChanges:=Fals e)



--

Dave Peterson
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
how to make excel 2007 open 2 wokbooks in 2 different windows Ofer Gal Excel Discussion (Misc queries) 1 May 5th 07 09:29 AM
If Then to check if a workbook is open Shawn Excel Discussion (Misc queries) 5 November 25th 06 04:29 PM
How check if workbook open? Ian Elliott Excel Programming 7 April 14th 06 08:54 PM
Check for open workbook georgio Excel Programming 2 November 20th 04 11:03 PM
How do I check opened wokbooks? TY Excel Programming 3 January 23rd 04 02:37 PM


All times are GMT +1. The time now is 04: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"