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.
Private Sub workbook_open()
'hide sheets
Dim sh As Worksheet
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Contents").Visible = True
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "Contents" Then
sh.Visible = False
End If
Next
End Sub
Private Sub workbook_open()
'hide sheets
Dim sh As Worksheet
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Contents").Visible = True 'make sure visible first
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "Contents" Then
sh.Visible = False
End If
Next
Application.ScreenUpdating = True
End Sub
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.