View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default hide sheet on file open

Make sure Contents is visible before you hide the others.

Option Explicit
Private Sub workbook_open()
dim sh as object
'hide sheets
Application.ScreenUpdating = False

me.Sheets("Contents").Visible = True

For Each sh In me.Sheets
if lcase(sh.name) = lcase("contents") then
'skip it
else
sh.Visible = False
end if
Next sh

application.screenupdating = true

End sub

(Untested, uncompiled. Watch for typos.

The Me keyword refers to the object that owns the code--in this case, it's the
workbook and is the same as ThisWorkbook.

Hein wrote:

Thanks very much. I got it to work with the following code:
Private Sub workbook_open()
'hide sheets
Application.ScreenUpdating = False

For Each sh In ThisWorkbook.Sheets
sh.Visible = False
Sheets("Contents").Visible = True
Next

The only problem that I encounter is that when the workbook is saved with
only the visible sheet showing and I re-open the workbook I get the following
error:
Run-time error '1004'
Unable to set the visible property of the worksheet class.

When I however make more sheets visible save and close it and then re-open
it, it works exactly how I want it to work.

I think that an If statement might work that will basicly ignore the code if
only the one sheet i.e. in my case "Contents" are visible. I am however not
sure how to write it in code.

Please assist.
Thanks

"Gord Dibben" wrote:

Either save it with the sheets hidden or use code in Thisworkbook module.

Private Sub Workbook_Open()
Sheets(Array("Sheet1", "Sheet3", "Sheet5")) _
..Visible = False
End Sub


Gord Dibben MS Excel MVP

On Mon, 20 Oct 2008 03:18:00 -0700, Hein
wrote:

How can I set a file that when I open it certain sheets are hidden and others
not?
Thanks




--

Dave Peterson