Hide/Show tab with VBA using password

Solved
caillasse147 Posted messages 71 Status Membre -  
caillasse147 Posted messages 71 Status Membre -
Hello everyone,

Thank you in advance for taking some time to help me solve my problem.

I have a macro available and it works perfectly so far, however I put a button in place, and with this I would like to show/hide my tabs when I press it by entering the correct password. I already have the beginning of my macro below but I can't figure out how to make it work:

Sub macro()
Password = InputBox("Password?", "User verification")
If Password = "cybo2016!" Then

If Password <> "cybo2016!" Then
MsgBox "Please enter the correct password!!"
End If
End Sub

Thank you

3 réponses

NaXiLeAn Posted messages 122 Status Membre 1
 
Hello,
- response from "GREG":
Hey, I found 2 nice tips to ask for a password when opening a sheet.

1st option: I hide my sheet

to write in the sheet module
'-----------------------------------------------------
Private Sub Worksheet_Activate()
SHOW_TDB_ASSO
End Sub

to write in the standard module
'------------------------------------------------------
Sub SHOW_TDB_ASSO()
Dim REP As String
REP = InputBox("PASSWORD", "OPENING RECAP ASSO SHEET")
If REP = "YOURPASSWORD" Then
Worksheets("TDB_ASSO").Visible = True
Columns("A:XFD").EntireColumn.Hidden = False
ActiveSheet.Cells(1, 1).Select
End If
'------------------------------------------------------
End Sub
Sub HIDE_TDB_ASSO()
Columns("A:XFD").EntireColumn.Hidden = True
Worksheets("TDB_ASSO").Visible = False
End Sub

2nd option: I only do it when activating the sheet (but in my opinion, it quickly becomes difficult if you regularly work with several sheets including this one ...)

to write in the sheet module
'-----------------------------------------------------
Private Sub Worksheet_Activate()
Dim REP As String
Columns("A:XFD").EntireColumn.Hidden = True
REP = InputBox("PASSWORD", "OPENING RECAP ASSO SHEET")
If REP = "YOURPASSWORD" Then
Columns("A:XFD").EntireColumn.Hidden = False
ActiveSheet.Cells(1, 1).Select
End If
End Sub

OF COURSE, THESE CODES NEED TO BE ADAPTED TO YOUR SHEET ;)

See you later ;)

--
NaXiLeAn_2.0
3