Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make sheets Very Hidden After A Certian Date! 2

Status
Not open for further replies.

APElliott

Technical User
Jul 9, 2002
165
GB
Hello,

Can I make all worksheets in a workbook 'very hidden' if todays date is greater than a date in a certain cell.

Cheers,

Andrew
 
In workbook open event

If date > range("A1").value then
for each sht in thisworkbook.sheets
sht.visible = xlveryhidden
next

HOWEVER - you can't make ALL sheets invisible - you have to leave 1 visible

Rgds, Geoff
Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
Want the best answers to your questions ? faq222-2244
 
Hi Andrew,

You can't hide all of the sheets in a workbook, but you can create a worksheet with a "Message" that informs your user that the workbook has expired. Make this the first worksheet in your workbook and set it's Visible property to xlSheetVeryHidden.

Then enter this code into a standard module in your VBA project:

Code:
Sub HideSheets_Now()
Dim sh As Worksheet
If Date < Sheets(&quot;Dates&quot;).Range(&quot;J2&quot;) Then Exit Sub
Sheets(1).Visible = True
For Each sh In ThisWorkbook.Worksheets
If sh.Index <> 1 Then ' This is your &quot;Message&quot; Sheet
    sh.Visible = xlSheetVeryHidden
End If
Next sh
End Sub

This will unhide your message sheet and hide all of the other sheets in the workbook so that they cannot be made visible again by using the Format->Sheets->Unhide... function.

In the Workbook_Open event for your workbook call the HideSheets_Now procedure.

And there you go!

Hope this helps!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Star to Mike for the further explanation and code

Rgds, Geoff
Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
Want the best answers to your questions ? faq222-2244
 
Thanx Geoff,

I'm honored to receive a star from the TopMaster of the week! [blush]

Congratulations again!

[cheers]



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
What will happen if the user does not Enable Macros?
I think it has to be a piece of code in the Before_Close event wich will make the sheets very hidden each time. On Auto_Open event the pages will become visible only if the user choose Enable Macros. Otherwise, only one sheet has to be visible telling him to choose &quot;Enable Macros&quot;.....

I hope this helps...
FaneDuru'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top