Peter Muller
Board Regular
- Joined
- Oct 15, 2018
- Messages
- 133
- Office Version
- 365
- Platform
- Windows
Good evening,
I am using the following code in my save and close command but am getting errors if a sheet is already closed, or if the columns are already hidden. I tried using “If, Then” commands in the code, but am obviously not doing it correctly. Please help.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Report").Select
Columns("K:P").EntireColumn.Hidden = True
Columns("Q:X").EntireColumn.Hidden = True
Columns("AC").EntireColumn.Hidden = True
Sheets("Data").Visible = False
Sheets("Procedure").Visible = False
Sheets("Report").Protect "Password"
Sheets("Analysis").Protect " Password "
Sheets("Budget").Protect " Password "
End Sub
I am using the following code in my save and close command but am getting errors if a sheet is already closed, or if the columns are already hidden. I tried using “If, Then” commands in the code, but am obviously not doing it correctly. Please help.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Report").Select
Columns("K:P").EntireColumn.Hidden = True
Columns("Q:X").EntireColumn.Hidden = True
Columns("AC").EntireColumn.Hidden = True
Sheets("Data").Visible = False
Sheets("Procedure").Visible = False
Sheets("Report").Protect "Password"
Sheets("Analysis").Protect " Password "
Sheets("Budget").Protect " Password "
End Sub