Hide Sheets When Excel is Shut down

AlextheTrader

New Member
Joined
Jul 25, 2014
Messages
11
I want to ride a code that automatically hides certain sheets when I open excel. In this case I want to hide "Sheet 1", "Sheet 2", and "Strings". I am very new with VBA so as simple as possible is prefered.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
AlextheTrader,

When you say 'open Excel' is that literal or are you saying 'hide sheets when I open this particular file'?

cheers

FarmerScott
 
Upvote 0
Alex,


this code goes in the 'This Workbook', of the file in question.

Code:
Private Sub Workbook_Open()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Set ws1 = Worksheets("Sheet1")
    If ws1.Visible = True Then
        ws1.Visible = False
  End If
  
Set ws2 = Worksheets("Sheet2")
    If ws2.Visible = True Then
        ws2.Visible = False
  End If
  
Set ws3 = Worksheets("Strings")
    If ws3.Visible = True Then
        ws3.Visible = False
  End If
  End Sub


Noting.... in your title you wanted the sheets hiden on close but in your detailed description you wanted the sheets hiden when the file is open.


Hope this helps,

FarmerScott
 
Last edited:
Upvote 0
An array might be a bit quicker
Code:
Private Sub Workbook_Open()
Dim myary As Variant, ws As Worksheet
Set myary = Sheets(Array("Sheet1", "Sheet2", "Strings"))
For Each ws In myary
    ws.Visible = xlSheetHidden
Next ws
End Sub
 
Upvote 0
Hi famerscott,

You do it without looping through the array, ie:

Code:
Sheets(Array("Sheet1", "Sheet2", "Strings")).Visible = False

Hi Michael,

You getting all this rain?

Cheers,

Robert
 
Upvote 0
Robert,

thanks.

Good rain thru NW NSW and western QLD. Not a drought buster but a nice start. Mrs is between Sydney and Canberra today and says heavy rain with lots of water in the paddocks.

FarmerScott
 
Upvote 0
Hi Robert
Darn, if I don't keep forgetting the collective action rather than the loop...:oops:

Yeah, we had almost 30mm over the weekend....didn't get a game in, so I'll have to take a flexi through the week !!!
I think Scott would be happier than me though !!
@Scott....sounds like you need to move the farm closer to Sydney...:LOL:
 
Upvote 0

Forum statistics

Threads
1,213,559
Messages
6,114,302
Members
448,564
Latest member
ED38

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