Hide worksheet

  • Thread starter Thread starter CAM
  • Start date Start date
C

CAM

Hello,

I have a workbook that I would like to hide a worksheet when the user open
the file based on the file name . There are three worksheets within the
workbook call Part A, Part B, and Part C. I only want to hide Part C
worksheet if the file name is call Schedule (Dept).xls when the user opens
the file. There will be other files name for example Schedule
(Company).xls or Schedule (Division).xls, but I only want to have Part C
worksheet hide when the file name contains within the parentheses (Dept).
How do I do that? Any tips will be appreciated. Thank you in advance.
 
Private Sub Workbook_Open()

With ThisWorkbook

If InStr(.Name, "(Dept)") > 0 Then
.Worksheets("Part C").Visible = xlSheetVisible
Else
.Worksheets("Part C").Visible = xlSheetHidden
End If
End With
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Back
Top