Private Sub Workbook_Open()
MsgBox Environ("UserName")
End Sub
Option Explicit
Option Compare Text
Private Sub Workbook_Open()
Dim RngSettings As Range, CellSettings
Dim TheUser As String
Dim TheSheets As Variant
Dim x As Integer
TheUser = Environ("UserName")
Set RngSettings = ThisWorkbook.Worksheets("Settings").Range("A2:A10")
For Each CellSettings In RngSettings
If CellSettings = TheUser Then
TheSheets = Split(CellSettings.Offset(0, 2), "/")
For x = 0 To UBound(TheSheets)
MsgBox TheSheets(x)
Next
End If
Next
End Sub
Option Explicit
Option Compare Text
Private Sub Workbook_Open()
Dim RngSettings As Range, CellSettings
Dim TheUser As String
Dim TheSheets As Variant
Dim x As Integer
Dim WS As Worksheet
TheUser = Environ("UserName")
Set RngSettings = ThisWorkbook.Worksheets("Settings").Range("A2:A10")
For Each CellSettings In RngSettings
If CellSettings = TheUser Then
If CellSettings.Offset(0, 1) = "ADMIN" Then
Exit Sub
End If
TheSheets = Split(CellSettings.Offset(0, 2), "/")
End If
Next CellSettings
For Each WS In ThisWorkbook.Worksheets
Select Case WS.Name
Case "Sommaire", "Tagada", "Tsoin Tsoin"
'Do Nothing on laisse ces feuilles visibles à tous
Case Else
WS.Visible = xlSheetVeryHidden
End Select
If TheSheets = Empty Then Exit Sub
For x = 0 To UBound(TheSheets)
If WS.Name = TheSheets(x) Then
WS.Visible = xlSheetVisible
End If
Next x
Next WS
End Sub
Sub ShowAllSheets()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Visible = xlSheetVisible
Next WS
End Sub
Function VerifMDP(Utilisateur As String, MdP As String) As Boolean
Dim rngTrouve As Range
VerifMDP = False 'par défaut, renvoie FAUX
With Sheets("parametrage") 'dans la feuille paramétrage
'cherche, colonne A, le nom d'utilisateur saisi
Set rngTrouve = .Columns(1).Cells.Find(Utilisateur, lookat:=xlWhole)
If rngTrouve Is Nothing Then 'si il ne trouve pas
VerifMDP = False 'la fonction renvoie faux
Else 's'il le trouve
'vérifie que le mot saisi feuille parametrgae colonne B est identique
'au mot de passe saisi dans l'USF
If rngTrouve.Offset(0, 1) <> MdP Then
VerifMDP = False 'si FAUX
Else
VerifMDP = True 'si VRAI
End If
End If
End With
End Function
'espère n'avoir à subir aucune interférence entre cette interdiction de départ selon l'utilisateur et les macros d'accès à certains onglets d'autres part
On Error GoTo GestionErreur
Sheets("BdD").Select
Exit Sub
GestionErreur:
msgbox "Accés interdit"
Sheets("OUVERTURE").Select