Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Excel crashes with .Close command

I am using Excel 97.

I have the following code :

For Each wb In Application.Workbooks
If wb.Name < ThisWorkbook.Name Then
wb.Close
End If
Next wb

At the end of the run of my macro, I have only two spreadsheets. The
Macro spreadsheet. And the report. Whenever it hits wb.close, and
spreadsheet is not the macro spreadsheet, Excel crashes.

I have tried several things. Including closing the spreadsheet by name
and not cycling the the spreadsheets. Nothing worked. C++ debugger
claims that it is a sharing violation. This is not true because I am
only one using the spreadsheet.

In order to get the job done. I save, then quit Excel. I do not want
this, I prefer the code above.

Does anyone know why wb.close might cause Excel to crash?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Excel crashes with .Close command

Rich,

my wild guess is that it's because you are trying to close the wb were the
macro is running
i.e., if your sub was called by the report from your macro book, then this
code will attempt to close the macro book, because Thisbook refers to the
active book - reports. but if macro book is closed, how can you continue to
run the code? So you probably screw stack or memory or something like that.

to solve this, add second test:

For Each wb In Application.Workbooks
If (wb.Name < ThisWorkbook.Name) and (wb< MyMacrobookName) Then

' where MyMacrobook is the name of your book with code, as a string
wb.Close
End If
Next wb


I am not sure about this, but give it a try
I would be curious to learn the results.

RADO



"Rich" wrote in message
om...
I am using Excel 97.

I have the following code :

For Each wb In Application.Workbooks
If wb.Name < ThisWorkbook.Name Then
wb.Close
End If
Next wb

At the end of the run of my macro, I have only two spreadsheets. The
Macro spreadsheet. And the report. Whenever it hits wb.close, and
spreadsheet is not the macro spreadsheet, Excel crashes.

I have tried several things. Including closing the spreadsheet by name
and not cycling the the spreadsheets. Nothing worked. C++ debugger
claims that it is a sharing violation. This is not true because I am
only one using the spreadsheet.

In order to get the job done. I save, then quit Excel. I do not want
this, I prefer the code above.

Does anyone know why wb.close might cause Excel to crash?



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
Copy command causes Excel to close Tom Excel Discussion (Misc queries) 1 June 25th 09 05:53 PM
Excel crashes on "Close" Visual Basic error 400 [email protected] Excel Discussion (Misc queries) 3 March 19th 08 03:45 PM
Open, Save and close Excel 2007 file with a cmd command Hugo Pinto Excel Discussion (Misc queries) 5 March 3rd 08 10:05 PM
Is there a command line "switch" To close Excel Randy Wayne Excel Discussion (Misc queries) 2 August 22nd 05 09:58 PM
Excel 2003 crashes when I close any worksheet Greg V Excel Discussion (Misc queries) 0 December 2nd 04 11:25 PM


All times are GMT +1. The time now is 07:31 AM.

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

About Us

"It's about Microsoft Excel"