1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Private Sub Workbook_Open()
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
'------------------------------- Intégration TCP -------------------------------------------
'---------------------------- Protection de la feuille -------------------------------------
MsgBox OSUserName
If OSUserName = "STAG3" Then 'si je fait partie de la prod
On Error Resume Next
ActiveSheet.Unprotect ("toto")
Range("Prod_Non_Autorise").Locked = True
Range("Prod_Autorise").Locked = False
ActiveSheet.Protect ("toto")
Else
On Error Resume Next
ActiveSheet.Unprotect ("toto")
Range("Prod_Non_Autorise").Locked = False
Range("Prod_Autorise").Locked = True
ActiveSheet.Protect ("toto")
End If
End Sub
'---------------------------- Récupération nom de session Windows --------------------------
Function OSUserName() As String 'extrait d'un code trouvé sur : http://forum.rue-montgallet.com/ruemontgallet/Programmation/vb-vba/resolu-recuperation-windows-sujet_22341_1.htm
Dim Buffer As String * 256
Dim BuffLen As Long
BuffLen = 256
If GetUserName(Buffer, BuffLen) Then _
OSUserName = Left(Buffer, BuffLen - 1)
End Function |
Partager