View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Hide/Unhide Sheet using VB

Hi,

Try this code. Ut hides all sheets except sheet1 on closing and unhides then
if macros are enabled. Sheet 1 should contain a suitable message to explain
that macros must be run to view sheets.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name < "Sheet1" Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub

Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = True
Next ws
End Sub

Mike

"Phendrena" wrote:

Hi,

I'm a complete novice with VB, however is it possible to use VB to unhide a
worksheet or worksheets if the script is run when the workbook is opened?
Thus if the script/macro isn't run then nothing is visable.

Thanks,