View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Macro for hidden sheet access

Hi Nigel,

AFAIK you cannot trap commandbar events other than your own custom menus.

Unhiding the sheet with "Format/Sheet/Unhide sheet" would trigger a
worksheet activate event. In this you could immediately unhide the sheet and
ask user for a password to unhide it. Store a worksheet level boolean to
store the state to get out of further activate events if visible is OK.

But why not hide the sheet as VeryHidden, user will not see it in
"Format/Sheet/Unhide sheet"

Try following attached to a button on another sheet. Note use of sheet
codename instead of sheet tab name, ie the one not in brackets in the vbe.
Sub Sheet2Visible()
Dim sPW As String
Dim sCap As String

If Sheet2.Visible = xlSheetVisible Then
Sheet2.Visible = xlSheetVeryHidden
sCap = "Unhide " & Sheet2.Name
Else
sPW = Application.InputBox("Enter password")
If sPW = "hello" Then
Sheet2.Visible = xlSheetVisible
sCap = "Hide " & Sheet2.Name
Else
MsgBox "incorrect password"
sCap = "Unhide Sheet2"
End If
End If
'On Error Resume Next
'assumes a forms button
ActiveSheet.Buttons(Application.Caller).Caption = sCap

End Sub

Regards,
Peter T

"Nigel" wrote in message
...
Hi,

Can anyone help me with a macro for accessing a hidden sheet? i have a
hidden sheet named "Cost Data". i have this sheet hidden as it holds cost
information regarding projects that other people are not privy too. i set

it
on a button to hide and another button with password to access it.

However, i
have found a flaw which is the password only works as long as the VBA

forms
are working. you have to close the form to enter certain data onto the

sheet.
From this point, you can unhide the sheet.

would it be possible to show a password protected box when
"Format/Sheet/Unhide sheet" is selected from the menu bar and if the

password
is incorrect, deny the sheet from being unhidden?

thanks in advance,


Nigel