PDA

View Full Version : complicate unhide sheet



lior03
02-12-2007, 01:37 AM
hello
i want to let a user unhide all sheets only if he provide a password .the password must be an integer.if he provide a wrong password he may get another try.
this is what i came up with:

Sub UnhideAllSheets()
Dim password As Integer
On Error GoTo err
password = InputBox("enter password to activate")
If password <> 1234 Then Exit Sub
If (password) = Empty Or Not IsNumeric(password) Then
Exit Sub
Dim wsSheet As Worksheet
For Each wsSheet In ActiveWorkbook.Worksheets
wsSheet.Visible = xlSheetVisible
Next wsSheet
End If
Exit Sub
err:
MsgBox "another try?", vbOKCancel
If vbCancel Then Exit Sub
If vbOK Then
End Sub


any suggestions?
thanks

JimmyTheHand
02-12-2007, 02:09 AM
How about this

Sub UnhideAllSheets()
Dim password As String
Dim TryAgain As Boolean
Dim wsSheet As Worksheet

TryAgain = True

On Error GoTo err
Do While TryAgain = True
password = InputBox("enter password to activate")
If password = "1234" Then
For Each wsSheet In ActiveWorkbook.Worksheets
wsSheet.Visible = xlSheetVisible
Next wsSheet
TryAgain = False
Else
If MsgBox("another try?", vbOKCancel) = vbCancel Then TryAgain = False
End If
Loop
Exit Sub
err:
MsgBox err.Number & " - " & err.Description
End Sub

lior03
02-13-2007, 03:38 AM
hello
i am trying to take this a little further.i want excel to check if there is a hidden sheet in the activeworkbook .if there none then exit sub with a msgbox.if there are some i want excel to use a msgbox and tell there are so and so hidden sheets, and unhide them.
i came up with a udf called ishide :

Function ishide() As Boolean
Dim wssheet As Worksheet
For Each wssheet In ActiveWorkbook.Worksheets
If wssheet.Visible = xlSheetVisible Then
ishide = False
Else: ishide = True
End If
Next
End Function

how do i incorporat this function into the procedure.
thanks

Bob Phillips
02-13-2007, 03:52 AM
Sub UnhideAllSheets()
Dim password As String
Dim wsSheet As Worksheet
Dim fFound As Boolean

password = InputBox("enter password to activate")
If password = "1234" Then
For Each wsSheet In ActiveWorkbook.Worksheets
If wsSheet.Visible <> xlSheetVisible Then
wsSheet.Visible = xlSheetVisible
fFound = True
End If
Next wsSheet
If Not fFound Then
MsgBox "No sheets hidden "
End If
End If
End Sub

moa
02-13-2007, 06:11 AM
Sub UnhideAllSheets()
Dim password As String
Dim sheetCount As Integer

sheetCount = 0
password = InputBox("enter password to activate")

If password = "1234" Then
If ishide(sheetCount) Then
MsgBox sheetCount & " sheets were hidden"
Else
MsgBox "No sheets hidden "
End If
End If
End Sub

Function ishide(sheetCount) As Boolean
Dim wssheet As Worksheet

ishide = False
For Each wssheet In ActiveWorkbook.Worksheets
If Not wssheet.Visible = xlSheetVisible Then
wssheet.Visible = xlSheetVisible
ishide = True
sheetCount = sheetCount + 1
End If
Next

End Function

lior03
11-11-2007, 07:16 AM
hello
i want to loop through al sheets and find a certain sheet with a name i specify.i want excel to search and activate a sheet

Sub indexm()
Dim r As String
r = InputBox("Type a sheet name, such as Sheet12", "looking for?")
If sheetExists(r) = True Then
If MsgBox(r & "is sheet number - " & Sheets(r).index, vbQuestion + vbOKCancel, " activate " & r & " now?") = vbOK Then
Sheets(r).Activate
End If
End If
End Sub


how can i tell the user the exists but hidden?
thanks

Bob Phillips
11-11-2007, 09:01 AM
check it for visible.

lior03
11-11-2007, 11:10 AM
how?

Bob Phillips
11-11-2007, 11:43 AM
If Worksheets(r).Visible = xlSheetVisible Then

lior03
11-11-2007, 11:40 PM
hello
how can i give excel a certain sheet name and do the following.if it is hidden unhide and activate if it is not hidden than activate.

Dim r As String
r = InputBox("Type a sheet name, such as Sheet12", "looking for?")
If sheetExists(r) = True Then
If Worksheets(r).Visible = xlVeryHidden Then
If MsgBox(r & "is sheet number - " & Sheets(r).index & " - but it is hidden,want to unhide?.", vbQuestion + vbOKCancel, " activate " & r & " now?") = vbOK Then
Sheets(r).Visible = xlSheetVisible
Sheets(r).Activate
End If
End If
End If


thanks