PC Review


Reply
Thread Tools Rate Thread

Code to Hide/Unhide Worksheet

 
 
Barb Reinhardt
Guest
Posts: n/a
 
      16th Jun 2009
I want to do something like this

Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
If myWS.Visible <> myHidden Then
myWS.Visible = myHidden
End If

End Sub

What I want to do is set it up so that myHidden only allows xlVisible,
xlHidden and xlVeryHidden (or whatever they are). How do I do that?

Thanks,
Barb Reinhardt
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      16th Jun 2009
'visible
myWS.Visible = 1
'hidden
myWS.Visible = 0
'very hidden
myWS.Visible = 2

To toggle between hide and unhide; try

myWS.Visible = not myWS.Visible

If this post helps click Yes
---------------
Jacob Skaria


"Barb Reinhardt" wrote:

> I want to do something like this
>
> Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
> If myWS.Visible <> myHidden Then
> myWS.Visible = myHidden
> End If
>
> End Sub
>
> What I want to do is set it up so that myHidden only allows xlVisible,
> xlHidden and xlVeryHidden (or whatever they are). How do I do that?
>
> Thanks,
> Barb Reinhardt

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      16th Jun 2009
Thanks, but I already have this information. I've seen a way somewhere on
how to have a variable default to some specified options for values when the
sub is called, such that only allows Hidden, Visible and VeryHidden. That's
what I'm looking for.

"Jacob Skaria" wrote:

> 'visible
> myWS.Visible = 1
> 'hidden
> myWS.Visible = 0
> 'very hidden
> myWS.Visible = 2
>
> To toggle between hide and unhide; try
>
> myWS.Visible = not myWS.Visible
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Barb Reinhardt" wrote:
>
> > I want to do something like this
> >
> > Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
> > If myWS.Visible <> myHidden Then
> > myWS.Visible = myHidden
> > End If
> >
> > End Sub
> >
> > What I want to do is set it up so that myHidden only allows xlVisible,
> > xlHidden and xlVeryHidden (or whatever they are). How do I do that?
> >
> > Thanks,
> > Barb Reinhardt

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      16th Jun 2009
a Hidden sheet can still be seen, and possibly unhidden by the user through
the Format/Sheets/Unhide menu - hidden sheets are listed here. However
VeryHidden sheets cannot be seen in this list. they can only be seen in the
workbooks property window and listed in code.

"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:712C64D2-0A65-4D0E-B39C-(E-Mail Removed)...
> I want to do something like this
>
> Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
> If myWS.Visible <> myHidden Then
> myWS.Visible = myHidden
> End If
>
> End Sub
>
> What I want to do is set it up so that myHidden only allows xlVisible,
> xlHidden and xlVeryHidden (or whatever they are). How do I do that?
>
> Thanks,
> Barb Reinhardt


 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      16th Jun 2009
xlSheetHidden
xlSheetVeryHidden
xlSheetVisible

If this post helps click Yes
---------------
Jacob Skaria


"Barb Reinhardt" wrote:

> Thanks, but I already have this information. I've seen a way somewhere on
> how to have a variable default to some specified options for values when the
> sub is called, such that only allows Hidden, Visible and VeryHidden. That's
> what I'm looking for.
>
> "Jacob Skaria" wrote:
>
> > 'visible
> > myWS.Visible = 1
> > 'hidden
> > myWS.Visible = 0
> > 'very hidden
> > myWS.Visible = 2
> >
> > To toggle between hide and unhide; try
> >
> > myWS.Visible = not myWS.Visible
> >
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "Barb Reinhardt" wrote:
> >
> > > I want to do something like this
> > >
> > > Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
> > > If myWS.Visible <> myHidden Then
> > > myWS.Visible = myHidden
> > > End If
> > >
> > > End Sub
> > >
> > > What I want to do is set it up so that myHidden only allows xlVisible,
> > > xlHidden and xlVeryHidden (or whatever they are). How do I do that?
> > >
> > > Thanks,
> > > Barb Reinhardt

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      16th Jun 2009
I understand all that. I'm still looking for code for something like this

Sub Test (myVal as variant)

where I can programmatically define several discrete options for myVal.
Only those values are allowed. I've seen it on other code, but just can't
find it. It's something that done outside of the procedure as I recall.

Barb Reinhardt

"Patrick Molloy" wrote:

> a Hidden sheet can still be seen, and possibly unhidden by the user through
> the Format/Sheets/Unhide menu - hidden sheets are listed here. However
> VeryHidden sheets cannot be seen in this list. they can only be seen in the
> workbooks property window and listed in code.
>
> "Barb Reinhardt" <(E-Mail Removed)> wrote in message
> news:712C64D2-0A65-4D0E-B39C-(E-Mail Removed)...
> > I want to do something like this
> >
> > Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
> > If myWS.Visible <> myHidden Then
> > myWS.Visible = myHidden
> > End If
> >
> > End Sub
> >
> > What I want to do is set it up so that myHidden only allows xlVisible,
> > xlHidden and xlVeryHidden (or whatever they are). How do I do that?
> >
> > Thanks,
> > Barb Reinhardt

>
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      16th Jun 2009
i kinda guessed you did

wasn;t sure what you needed though

"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:AD0B4985-746A-4CE9-BCA0-(E-Mail Removed)...
> I understand all that. I'm still looking for code for something like this
>
> Sub Test (myVal as variant)
>
> where I can programmatically define several discrete options for myVal.
> Only those values are allowed. I've seen it on other code, but just can't
> find it. It's something that done outside of the procedure as I recall.
>
> Barb Reinhardt
>
> "Patrick Molloy" wrote:
>
>> a Hidden sheet can still be seen, and possibly unhidden by the user
>> through
>> the Format/Sheets/Unhide menu - hidden sheets are listed here. However
>> VeryHidden sheets cannot be seen in this list. they can only be seen in
>> the
>> workbooks property window and listed in code.
>>
>> "Barb Reinhardt" <(E-Mail Removed)> wrote in
>> message
>> news:712C64D2-0A65-4D0E-B39C-(E-Mail Removed)...
>> > I want to do something like this
>> >
>> > Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
>> > If myWS.Visible <> myHidden Then
>> > myWS.Visible = myHidden
>> > End If
>> >
>> > End Sub
>> >
>> > What I want to do is set it up so that myHidden only allows xlVisible,
>> > xlHidden and xlVeryHidden (or whatever they are). How do I do that?
>> >
>> > Thanks,
>> > Barb Reinhardt

>>
>>

 
Reply With Quote
 
keiji kounoike
Guest
Posts: n/a
 
      17th Jun 2009
This is not what you saw someone's code. but what about checking you
arguments before starting procedure like below?

Sub testcall()
test 123
End Sub

Sub test(myval As Variant)
Select Case myval
Case xlSheetHidden, xlSheetVisible, xlSheetVeryHidden
Case Else
'Msgbox is not needed, just for test
MsgBox "Wrong arg:" & myval
Exit Sub
End Select

'start your code from here
MsgBox myval

End Sub

Keiji

Barb Reinhardt wrote:
> I understand all that. I'm still looking for code for something like this
>
> Sub Test (myVal as variant)
>
> where I can programmatically define several discrete options for myVal.
> Only those values are allowed. I've seen it on other code, but just can't
> find it. It's something that done outside of the procedure as I recall.
>
> Barb Reinhardt
>
> "Patrick Molloy" wrote:
>
>> a Hidden sheet can still be seen, and possibly unhidden by the user through
>> the Format/Sheets/Unhide menu - hidden sheets are listed here. However
>> VeryHidden sheets cannot be seen in this list. they can only be seen in the
>> workbooks property window and listed in code.
>>
>> "Barb Reinhardt" <(E-Mail Removed)> wrote in message
>> news:712C64D2-0A65-4D0E-B39C-(E-Mail Removed)...
>>> I want to do something like this
>>>
>>> Sub HideUnhideSheets(myWS As Excel.Worksheet, myHidden As Variant)
>>> If myWS.Visible <> myHidden Then
>>> myWS.Visible = myHidden
>>> End If
>>>
>>> End Sub
>>>
>>> What I want to do is set it up so that myHidden only allows xlVisible,
>>> xlHidden and xlVeryHidden (or whatever they are). How do I do that?
>>>
>>> Thanks,
>>> Barb Reinhardt

>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hide, unhide column or row after protect worksheet tiny Microsoft Excel Misc 4 14th May 2009 04:23 PM
hide, unhide column or row after protect worksheet tiny Microsoft Excel Misc 0 14th May 2009 03:15 PM
Can I hide a worksheet and set a passwd to unhide it? puneetarora_12 Microsoft Excel Misc 2 24th Jul 2005 06:06 PM
Can I hide a worksheet and set a passwd to unhide it? puneetarora_12 Microsoft Excel Worksheet Functions 1 24th Jul 2005 08:50 AM
How to hide a worksheet and set a password to protect someone else unhide it. Shu Microsoft Excel Programming 2 28th Mar 2004 04:14 AM


Features
 

Advertising
 

Newsgroups
 


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