sheet hide unhide macro

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Sheet hide unhide Macro

Sheet hide unhide Macro

resolvedResolved · Urgent Priority · Version 2010

Sanjay has attended:
Excel VBA Introduction course
Excel VBA Intermediate course

Sheet hide unhide Macro

Hi,

Could you please help me to create 2 macro for a work book which has mulitple sheet (Sheet1,sheet2......sheet10)

First macro to hide the few macro from the workbook.
Second macro to unhide the hidden macro.

please let me know if you need any other information.

Thanks

RE: Sheet hide unhide Macro

any update on my query ?

RE: Sheet hide unhide Macro

Hi Sanjay

Thanks for your question!

Unfortnately, due to the nature of the content of your question, the relevant trainer won't be available to answer until tomorrow. They will try to get back to you as soon as possible.

Sorry for the inconvenience.

Regards,

Sarah
Excel Trainer

RE: Sheet hide unhide Macro

Hi Sarah,

Do we have any update on my query?

Thanks
Sanjay

RE: Sheet hide unhide Macro

Hi Sanjay,

Thank you for the forum question and I am sorry that you have had to wait for an answer.

I am a little bit confused of what you want. Do you want to hide sheets or macros?

If it is sheets you want to hide/unhide

To hide:

ActiveWorkbook.Sheets("Name").Visible = xlSheetVeryHidden

To unhide

ActiveWorkbook.Sheets("Name").Visible =xlSheetVisible

To hide macros programmatically is a complicated task, and you should just use a password to hide the module.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Sheet hide unhide Macro

Thanks Jane for your reply.

My issue is that I have a workbook which have 45 sheets and I have to use a macro so that i can hide approx 30 Sheets in one go.so the users cant access those sheets.similarly another macro will unhide those sheets for modification.

I hope my requirement is clear now for you.

Thanks
Sanjay

Edited on Wed 1 Nov 2017, 10:11

RE: Sheet hide unhide Macro

Hi Sanjay,

The code as written in my answer:

To hide:

ActiveWorkbook.Sheets("Name").Visible = xlSheetVeryHidden

To unhide

ActiveWorkbook.Sheets("Name").Visible =xlSheetVisible


You can use loops and a decision code: (you will have to add/amend the sheet numbers in the Case line)



Sub HideSheet()

Dim Sh As Worksheet

For Each Sh In Worksheets


Select Case Sh.Index


Case 2, 5, 6

Sh.Visible = xlSheetVeryHidden

End Select

Next




End Sub


Sub UnhideAllSheets()
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws

End Sub



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Sheet hide unhide Macro

Thanks Jane.

Will check and let you know if i have any issue.

Thanks again.

Sanjay

RE: Sheet hide unhide Macro

Hi Sanjay,

You can also add the following at the top of your module to hide the macro from Excel buttons and front end access in addition to protecting your code.

Option Private Module

MSDN explanation is at:
https://msdn.microsoft.com/en-us/library/aa266185 (v=vs.60).aspx

Kind regards
Fiona

RE: Sheet hide unhide Macro

Thanks..

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Stop Formula Returning A "#DIV/0" Error

If a formula returns a #DIV/0 error message there is a way to avoid such results.

For example the formula =A1/B1 will return a #DIV/0 if B1 is empty or a zero.

If you protect your formulas with the ISERROR function, the formula will then look like this:

=IF(ISERROR(A1/B1),0,A1/B1)

In plain English: should the result of A1 divided by B1 be an error change the result to 0 else show the result of A1/B1.

View all Excel hints and tips


Server loaded in 0.08 secs.