• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

A macro for let just users that have a password to unhide the hide sheets

hoomantt

Member
i have a file and i want a macro (vb) code that dont let any user that have not the password to unhide the hide sheets.

when they want to unhide the sheets excel wants a password for it . . .

thanks dear proffessors.
 
Something like this pair of macros should help you get started. The first is to hide all the sheets, the latter is to unhide them via password. A user would need to use VBA to unhide the sheets.

CAUTION: There is no way to make data completely secure in XL, only make it more difficult to access. The method below can be bypassed quickly by anyone who really wanted to and knows VBA. You can make it more difficult by protection the VB code, and protecting the workbook, but these will only slow someone down.

In summary, if this is to "protect" in the sense that you don't want someone accidentally screwing something up, proceed. If you are trying to hide sensitive information, XL is not the way to go.

[pre]
Code:
Option Private Module
Option Explicit

Sub VeryHideSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
'What sheet will remain visible?
If ws.Name <> "Main Sheet" Then
'Everything else is very hidden, so only
'can become unhidden through VBA
ws.Visible = xlVeryHidden
End If
Next ws
End Sub

Sub UnHidePass()
Dim xUser As String
Dim ws As Worksheet
'What is the password?
Const MyPass = "1234"

'Query the user. Proceed no matter what the user inputs
On Error Resume Next
xUser = InputBox("What is the password?", "Password")
On Error GoTo 0

If xUser <> MyPass Then
MsgBox "Invalid Password"
Exit Sub 'Wrong
End If

For Each ws In ThisWorkbook.Worksheets
ws.Visible = True
Next ws

End Sub
[/pre]
 
Hi, hoomantt!

Adding to what Luke M wrote, you can read this:

http://chandoo.org/forums/topic/macro-to-hideunhide-in-protected-sheet-produces-error-code#post-37901

Regards!
 
Back
Top