ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide/Unhide Sheet using VB (https://www.excelbanter.com/excel-programming/402389-hide-unhide-sheet-using-vbulletin.html)

Phendrena

Hide/Unhide Sheet using VB
 
Hi,

I'm a complete novice with VB, however is it possible to use VB to unhide a
worksheet or worksheets if the script is run when the workbook is opened?
Thus if the script/macro isn't run then nothing is visable.

Thanks,

Bob Phillips

Hide/Unhide Sheet using VB
 
The standard way to approach this is as follows.
- create a worksheet with a message on explaining that for this workbook to
run it needs macros enabled, maybe even a few screenshots
- hide all other worksheets]
- add some code in the Workbook_Open event that un hides the other sheets,
but hides that sheet.


What happens is that if they do not enable macros, they will only see the
warning sheet, telling them how to do it. If the enable macros, it will
startup as the workbook it should be


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Phendrena" wrote in message
...
Hi,

I'm a complete novice with VB, however is it possible to use VB to unhide
a
worksheet or worksheets if the script is run when the workbook is opened?
Thus if the script/macro isn't run then nothing is visable.

Thanks,




Mike H

Hide/Unhide Sheet using VB
 
Hi,

Try this code. Ut hides all sheets except sheet1 on closing and unhides then
if macros are enabled. Sheet 1 should contain a suitable message to explain
that macros must be run to view sheets.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name < "Sheet1" Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub

Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = True
Next ws
End Sub

Mike

"Phendrena" wrote:

Hi,

I'm a complete novice with VB, however is it possible to use VB to unhide a
worksheet or worksheets if the script is run when the workbook is opened?
Thus if the script/macro isn't run then nothing is visable.

Thanks,


Roxy

Hide/Unhide Sheet using VB
 
I have a command button to where I would like to specify which sheet I would
like to unhide. Example the sheet I would like to unhide is called Extra
Earned Income Method 2.

Thanks

"Mike H" wrote:

Hi,

Try this code. Ut hides all sheets except sheet1 on closing and unhides then
if macros are enabled. Sheet 1 should contain a suitable message to explain
that macros must be run to view sheets.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name < "Sheet1" Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub

Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = True
Next ws
End Sub

Mike

"Phendrena" wrote:

Hi,

I'm a complete novice with VB, however is it possible to use VB to unhide a
worksheet or worksheets if the script is run when the workbook is opened?
Thus if the script/macro isn't run then nothing is visable.

Thanks,



All times are GMT +1. The time now is 04:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com