Hello AKRAMI,
I added two more macros to this workbook. One macro hides all sheets except Fueil1. The other macro shows only the sheets for the user according to the Database worksheet.
ShowUsersSheet is called in the "Validate" button on UserForm1. HideSheets is called in the "Workbook_BeforeClose" event.
Here is the code that was added to Module1...
Sub ShowUserSheets(ByVal UserName As String)
Dim c As Long
Dim HeaderRow As Range
Dim UserRow As Range
Dim Wks As Worksheet
Set Wks = Worksheets("DATABASE")
Set HeaderRow = Wks.Range("A1", Wks.Cells(1, Columns.Count).End(xlToLeft))
Set UserRow = Wks.Columns(1).Cells.Find(UserName, , xlValues, xlWhole, xlNext, xlByRows, False, False, False)
If UserRow Is Nothing Then Exit Sub
If UserRow.Cells(1, 3) = True Then Exit Sub
For c = 4 To HeaderRow.Columns.Count
If UCase(UserRow.Cells(1, c)) = "X" Then
ThisWorkbook.Worksheets(HeaderRow.Cells(1, c).Text).Visible = -1
End If
Next c
End Sub
Sub HideSheets()
Dim Wks As Worksheet
For Each Wks In ThisWorkbook.Worksheets
If Wks.Name <> "Feuil1" Then
Wks.Visible = xlSheetVeryHidden
End If
Next Wks
End Sub
Bookmarks