Toggling xlVeryHidden

B

Bob

I am trying to write a macro for use in Excel 2003 & 2007 that will toggle
between hiding (using xlVeryHidden) and unhiding a specific worksheet
(Sheet2).

I know how to perform a "normal" hide/unhide using the following code:

Sub HideUnhide()
Sheets("Sheet2").Visible = Not _
Sheets("Sheet2").Visible
End Sub

But I don't know how to incorporate xlVeryHidden. I would greatly
appreciate any help.

Thanks,
Bob
 
T

Tom Hutchins

Try

Sub HideUnhide()
With Sheets("Sheet2")
If (.Visible = xlVeryHidden) Or (.Visible = False) Then
.Visible = True
Else
.Visible = xlVeryHidden
End If
End With
End Sub

Hope this helps,

Hutch
 
J

Jacob Skaria

Bob, try the below..

Sub HideUnhide()
Sheets("Sheet2").Visible = IIf(Sheets("Sheet2").Visible = _
True, xlSheetVeryHidden, True)
End Sub
 
O

ozgrid.com

It doesn't :) Should be;

Sub HideUnhide()
With Sheet2
If .Visible = True Then
.Visible = xlSheetVeryHidden
Else
.Visible = True
End If
End With
End Sub

I was just trying to avoid the IIf, and use the CodeName so users cannot
break the macro by renaming or moving the Sheet. I have read on the MS site
somewhere that's it rather clunky compared to If Else statements. I.e looks
can be deceiving :)
 
B

Bob

Jacob - Thanks for your help! Being a relative novice to VBA I am not
familiar with "IIF" and need to read up on it. I like your efficient code.
Thanks again!

Regards,
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top