On Close or On Open

RandyD123

Active Member
Joined
Dec 4, 2013
Messages
289
Office Version
  1. 2016
Platform
  1. Windows
Looking for a VBA to hide two tabs on close or on open of my workbook. Tabs that should be hidden are "Sheet1" and Sheet2". Thank you for any help.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet1").Visible = 2
Sheets("Sheet2").Visible = 2
End Sub

Private Sub Workbook_Open()
Sheets("Sheet1").Visible = 2
Sheets("Sheet2").Visible = 2
End Sub
 
Upvote 0
Solution
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet1").Visible = 2
Sheets("Sheet2").Visible = 2
End Sub

Private Sub Workbook_Open()
Sheets("Sheet1").Visible = 2
Sheets("Sheet2").Visible = 2
End Sub
Thank you, works perfectly!!! One quick question, do I need both because I notice "on close" it's done, so I don't see how "on open" would matter?
 
Upvote 0
I know that you've written on close OR on open. I give you both.
It is up to you.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top