View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272[_2_] ryguy7272[_2_] is offline
external usenet poster
 
Posts: 56
Default How can I force a workbook to close?

On Jul 22, 2:50*pm, Dave Peterson wrote:
I've never seen excel open multiple files with the same name in the same
instance. *And I bet if you check again, there's either a difference in names or
you have multiple instances open.

I'm not sure what you're doing, but if don't want to close excel, you could
check to see how many workbooks are open in the _BeforeClose event.

* * *If Workbooks.Count 2 Then

Might be sufficient to check???

On 07/22/2010 13:07, ryguy7272 wrote:





How can I force a workbook to close?


I run this code:
* * ThisWorkbook.EnableAutoRecover = False
* * ThisWorkbook.Saved = True
* * ThisWorkbook.Close


That triggers this:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.name = "MainFile.xls" Then
* * * * *Application.Quit
End If
End Sub


But that kills the whole Excel-application! *If I open Excel and then
goto Start *Office *Excel, I have 2 instances of Excel open. *I can
end one instance pretty easy. *However, if I have two workbooks open
within the SAME instance, Excel doesn’t seem to be able to close one
file and keep the other open. *In fact, Excel opens several new files,
all named ‘MainFile.xls’. *VERY ANNOYING!!!


How can I shut down any file named ‘MainFile.xls’ and keep other Excel
files open?


Thanks!
Ryan--


--
Dave Peterson- Hide quoted text -

- Show quoted text -



Thanks George and Dave! I tried both of your recommendations, and
many others that i've seen on the Web. When I close Excel each time,
no matter what I do, I always get a file poping up called
'MainFile.xls' and I'll get another file named 'MainFile(1).xls'...if
I'm in the same instance of Excel. If I have TWO instances of Excel
running, everything is perfect. This Excel behavior is highly
unusual..... I've never seen anything like it...

Any other ideas?