View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Issue on Close Q

First, you haven't declared the variable 'ws'. Putting "Option Explicit" as
the very first line in the code module will require to explicitly declare
your variable. Do this, always.

You code will blow up if you don't have a sheet named "Splash" (test the
sheet in case it contains leading/trailing spaces, a misspelled name, etc).
If there is no sheet named "Splash" your code will attempt to set
xlVeryHidden on every sheet. A workbook must always have at least one
visible sheet. You'll blow up on the last sheet.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Sean" wrote in message
oups.com...
I have the following code that, on close, it hides all the Sheets
except Splash. Problem is I'm getting a debug on -
ws.Visible = xlVeryHidden

It says - Unable to set the visible property of the worksheet class

I've all sheets protected and running 2003



Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sh As Worksheet
For Each ws In Worksheets
If ws.Name = "Splash" Then
ws.Visible = True
Else
ws.Visible = xlVeryHidden
End If
Next

End Sub