+ Reply to Thread
Results 1 to 6 of 6

Auto hide sheets

  1. #1
    tcbootneck
    Guest

    Auto hide sheets

    Hello

    Basic and simple question, but have forgotten.

    How do you hide any open sheets, when opening a workbook?

    Thanks

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello tcbootneck,

    Add the following code to your Workbook's Open event procedure.

    Dim Wks As Worksheet
    For Each Wks In ThisWorkbook.Worksheets
    If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
    Next Wks

    This will check each Worksheet and test if it is visible. If it is visible then the macro will hide the Worksheet. Your final code result will look like this...

    Private Sub Workbook_Open()
    Dim Wks As Worksheet
    For Each Wks In ThisWorkbook.Worksheets
    If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
    Next Wks
    End Sub

    Sincerely,
    Leith Ross

  3. #3
    tcbootneck
    Guest

    Re: Auto hide sheets

    Hi Leith

    Just the job. Thanks

    "Leith Ross" wrote:

    >
    > Hello tcbootneck,
    >
    > Add the following code to your Workbook's Open event procedure.
    >
    > Dim Wks As Worksheet
    > For Each Wks In ThisWorkbook.Worksheets
    > If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
    > Next Wks
    >
    > This will check each Worksheet and test if it is visible. If it is
    > visible then the macro will hide the Worksheet. Your final code result
    > will look like this...
    >
    > Private Sub Workbook_Open()
    > Dim Wks As Worksheet
    > For Each Wks In ThisWorkbook.Worksheets
    > If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
    > Next Wks
    > End Sub
    >
    > Sincerely,
    > Leith Ross
    >
    >
    > --
    > Leith Ross
    > ------------------------------------------------------------------------
    > Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
    > View this thread: http://www.excelforum.com/showthread...hreadid=553001
    >
    >


  4. #4
    Greg Wilson
    Guest

    Re: Auto hide sheets

    Don't you get an error or am I missing something? I don't think you can hide
    all worksheets at the same time. I assumed Leith had an oversight. Thought it
    should be something like:

    Private Sub Workbook_Open()
    Dim Wks As Worksheet
    For Each Wks In ThisWorkbook.Worksheets
    If Wks.Name <> "Sheet1" Then
    If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
    End If
    Next Wks
    End Sub

    Greg


    "tcbootneck" wrote:

    > Hi Leith
    >
    > Just the job. Thanks
    >
    > "Leith Ross" wrote:
    >
    > >
    > > Hello tcbootneck,
    > >
    > > Add the following code to your Workbook's Open event procedure.
    > >
    > > Dim Wks As Worksheet
    > > For Each Wks In ThisWorkbook.Worksheets
    > > If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
    > > Next Wks
    > >
    > > This will check each Worksheet and test if it is visible. If it is
    > > visible then the macro will hide the Worksheet. Your final code result
    > > will look like this...
    > >
    > > Private Sub Workbook_Open()
    > > Dim Wks As Worksheet
    > > For Each Wks In ThisWorkbook.Worksheets
    > > If Wks.Visible = xlSheetVisible Then Wks.Visible = xlSheetHidden
    > > Next Wks
    > > End Sub
    > >
    > > Sincerely,
    > > Leith Ross
    > >
    > >
    > > --
    > > Leith Ross
    > > ------------------------------------------------------------------------
    > > Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
    > > View this thread: http://www.excelforum.com/showthread...hreadid=553001
    > >
    > >


  5. #5
    AA2e72E
    Guest

    Re: Auto hide sheets


    A workbooks MUST have one visible sheet, either a Sheet or a Worksheet.

  6. #6
    Greg Wilson
    Guest

    Re: Auto hide sheets

    I take that as a confirmation. Perhaps tcbootneck has a chart sheet and so
    didn't get an error?

    Greg

    "AA2e72E" wrote:

    >
    > A workbooks MUST have one visible sheet, either a Sheet or a Worksheet.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1