View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rich[_16_] Rich[_16_] is offline
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?