Results 1 to 4 of 4

Thread: VBA to hide sheets when save button is pressed
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    May 2019
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA to hide sheets when save button is pressed

    Is there a VBA or macro that can hide certain sheets when the save button is pressed? Thank you

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    23,961
    Post Thanks / Like
    Mentioned
    408 Post(s)
    Tagged
    42 Thread(s)

    Default Re: VBA to hide sheets when save button is pressed

    How about
    Code:
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
       Dim Ws As Worksheet
       
       For Each Ws In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
          Ws.Visible = xlSheetHidden
       Next Ws
    End Sub
    Change the names in red to match your sheet names
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    New Member
    Join Date
    May 2019
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to hide sheets when save button is pressed

    like a charm, thank you!

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    23,961
    Post Thanks / Like
    Mentioned
    408 Post(s)
    Tagged
    42 Thread(s)

    Default Re: VBA to hide sheets when save button is pressed

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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