+ Reply to Thread
Results 1 to 7 of 7

VBA to Hide Sheet1 & 2 after a 'save as' has been performed

  1. #1
    Registered User
    Join Date
    10-09-2016
    Location
    Preston, England
    MS-Off Ver
    2010, 2013 & 2016
    Posts
    30

    Question VBA to Hide Sheet1 & 2 after a 'save as' has been performed

    Hi,
    I have seen this happen before on a workbook I have used.

    I am after hiding 2 sheets once the 'Save as' has been performed. on the workbook I used with this on, you had to 'save as', close and then re open the new saved as file and the sheets in question have been hidden (the where open to begin with, you entered the source data and then saved as).

    Does any one have any ideas?

    Thank you
    Last edited by Jwilf; 10-18-2016 at 02:42 PM. Reason: Solved

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: VBA to Hide Sheet1 & 2 after a 'save as' has been performed

    I am confused by your explanation. Do you wish to hide sheets after saving the workbook, but keep the workbook open. In this case, the sheets are not hidden when the workbook is opened. Or do you wish for the sheets to be hidden when the workbook is opened? Please clarify in the simplest terms.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    10-09-2016
    Location
    Preston, England
    MS-Off Ver
    2010, 2013 & 2016
    Posts
    30
    Quote Originally Posted by alansidman View Post
    I am confused by your explanation. Do you wish to hide sheets after saving the workbook, but keep the workbook open. In this case, the sheets are not hidden when the workbook is opened. Or do you wish for the sheets to be hidden when the workbook is opened? Please clarify in the simplest terms.

    Hi sorry, reading back through my post i realised i didnt make it clear enough.

    I have created a report template for some one else to use. Sheet 1 and 2 are the data in put sheets, the rest of the sheets contain all of the pivot tables and charts.

    Because some one else will be using the template i would like a macro that automaticaly hides sheet 1&2 in the saved as document. So all sheets in the original document remain open (as this document is the template to be used over and over again) but when they save a copy, and then open that copy the sheets are hidden (the saved copy is the report to present to others).

    I hope that makes more sense.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: VBA to Hide Sheet1 & 2 after a 'save as' has been performed

    Assume data sheets to be hidden are in Sheet1 and Sheet2.

    Open the VBE and place this code in the Workbook_BeforeSave Event

    Please Login or Register  to view this content.
    To unhide these sheets,
    Insert this VBA in the Modules

    Please Login or Register  to view this content.
    For the second code:


    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

  5. #5
    Registered User
    Join Date
    10-09-2016
    Location
    Preston, England
    MS-Off Ver
    2010, 2013 & 2016
    Posts
    30

    Re: VBA to Hide Sheet1 & 2 after a 'save as' has been performed

    Perfect,
    thank you for your help

  6. #6
    Registered User
    Join Date
    10-09-2016
    Location
    Preston, England
    MS-Off Ver
    2010, 2013 & 2016
    Posts
    30

    Re: VBA to Hide Sheet1 & 2 after a 'save as' has been performed

    sorry to pester.
    I have the code in the workbook, I don't want the code to work when I save the original workbook as this is the template to be used time and time again and the first 2 sheets need to always be open in order for the other user to input the data. I have a save as code in the work book linked to a button (see below). the save as copy is the report this user will then send on to other people to view, hence why I want the data input sheets to be hidden in this version.
    The user only has data input skills and does not know how to add vba or even right click the sheet select hide so I am trying to automate as much as I can.

    Thanks in advance

    Please Login or Register  to view this content.

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: VBA to Hide Sheet1 & 2 after a 'save as' has been performed

    Maybe

    Please Login or Register  to view this content.
    Then unhide the sheets before closing the original file or unhide them on Worksheet_Open event

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Hide specific Rows in Sheet1 + hide 5 more in Sheet2
    By bluesurger in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 06-02-2014, 07:19 AM
  2. Hide all sheets (except Sheet1) on workbook Save?
    By DannyH1984 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2013, 07:03 AM
  3. =+Sheet1!A1+Sheet1!B1+Sheet1!C1 macro to convert all linked ref to Values
    By chriszoma in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2013, 02:44 PM
  4. merge book1,sheet1,book2,sheet1,book3,sheet1 ect
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 01:30 PM
  5. Hide value (and row) in Sheet1 if it is NOT in Sheet2
    By GalmOne in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 08-02-2012, 02:04 PM
  6. Hide columns on sheet2 based on cell on sheet1?
    By proepert in forum Excel General
    Replies: 4
    Last Post: 01-25-2010, 09:00 AM
  7. Save down sheet1 without it opening?
    By cam8 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2009, 06:46 PM

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