Hide/Unhide Sheets Form

D

dbarelli

Hi everyone, I'm trying to make a form with two listbox and fill the
with all sheets in a workbook (visible and hidden). See below the cod
in form_activate line:


Code
-------------------

Dim x As Integer
Dim vhojactiva As String

Application.ScreenUpdating = False
vhojactiva = ActiveSheet.Name

For x = 1 To Sheets.Count
Sheets(Array(x)).Select
If ActiveSheet.Visible = -1 Then
lstvisible.AddItem (ActiveSheet.Name)
Else
lsthidden.AddItem (ActiveSheet.Name)
End If
Next x
Sheets(vhojactiva).Select
Application.ScreenUpdating = True

-------------------


...the problem is when I try to select a hidden sheet. How can I do ?
Any idea is welcome.

Thanks and Regards
Daniel
 
B

Bob Phillips

Dim x As Integer

Application.ScreenUpdating = False

For x = 1 To Sheets.Count
If Sheets(x).Visible = xlSheetVisible Then
lstvisible.AddItem (ActiveSheet.Name)
Else
lsthidden.AddItem (ActiveSheet.Name)
End If
Next x

Application.ScreenUpdating = True


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
G

Guest

there is no need to select the sheets (and no, you can't select a hidden sheet)

Dim x As Integer
Dim vhojactiva As String

vhojactiva = ActiveSheet.Name

For x = 1 To Sheets.Count
If sheets(x).Visible = -1 Then
lstvisible.AddItem sheets(x).Name
Else
lsthidden.AddItem sheets(x).Name
End If
Next x
 

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