Worksheet Hide / Unhide

mrowe

Board Regular
Joined
Feb 17, 2002
Messages
232
Hi,

Being Friday, by brain has ground to a halt (again).

What I want to do is hide sheet3 if it is visable or do nothing if it is hidden on each workbook close.

I thought of using a flag like if visable then 1 else 0
If 1 then show else hide etc..

Any ideas?

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Sheets("Sheet3").Select
ActiveWindow.SelectedSheets.Visible = False

End Sub

Thanks
Matt
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
At the end, anyway, you want to hide it ??
So no condition required (if I am not too tired also...)

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Thisworkbook.Sheets("Sheet3").visible=false
End Sub
 
Upvote 0
I don;t think you need to test its visibility. Your code will already hide it if it's visible and do nothing if it isn't.

If you want to toggle the visibility:

Code:
With Sheets("Sheet3")
   .Visible = Not .Visible
End With
 
Upvote 0
this is ok but it's not visable all the time so I need some error trapping to look at it to see if it's visable or not first
 
Upvote 0
Then you have :

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set mysh=Thisworkbook.Sheets("Sheet3")
If mysh.visible =true then
mysh.visible=false
'any other action
Else
'any action
End if
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top