View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default Select range fails

"Geoff" wrote in message
...
The code is in ThisWorkbook. There are problems when quitting Excel with
several wbooks open. If this is the only workbook open the code runs ok
but
fails if there are others open as well. I thought by placing it in
ThisWorkbook module it was specific but maybe not. How should I qualify
the
Select statement please?

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Range("A100").Select 'Fails here if other
wbooks
are open

ActiveWindow.DisplayGridlines = False

Application.DisplayAlerts = False
ActiveWorkbook.Save
Application.DisplayAlerts = True

End Sub


Hi Geoff,

You have to activate a worksheet before you can select a cell on it. I
suspect this is the problem. Change your select code to the following:

With Sheets(Sheets.Count)
.Activate
.Range("A100").Select
End With

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm