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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| Private Sub Workbook_open()
On Error Resume Next
Dim strWbName As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'---------------MultiUser----------------
If Not ThisWorkbook.MultiUserEditing = True Then
Application.DisplayAlerts = False
With ThisWorkbook
If .KeepChangeHistory Then .KeepChangeHistory = False
If .ConflictResolution Then .ConflictResolution = xlLocalSessionChanges 'Modif de l'utilisateur local sont tjs acceptées
If .PersonalViewListSettings Then .PersonalViewListSettings = False
If .PersonalViewPrintSettings Then .PersonalViewPrintSettings = False
If .HighlightChangesOnScreen Then HighlightChangesOnScreen = True 'Modif non surligné a l'écran
.HighlightChangesOptions When:=xlAllChanges
If .ListChangesOnNewSheet Then .ListChangesOnNewSheet = True
If .AutoUpdateFrequency Then .AutoUpdateFrequency = 5
End With
'Partager
Call Partager
End If
' ..........................
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Dim varUsers As Variant
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If ThisWorkbook.MultiUserEditing = True Then
If IsNumeric(UBound(varUsers, 1)) = True Then
If Not UBound(varUsers, 1) > 1 Then
Call DéPartager
End If
End If
End If
End Sub
Sub Partager()
On Error Resume Next
Application.DisplayAlerts = False
MsgBox ("passe en mode partagé : ")
If Not ThisWorkbook.MultiUserEditing = True Then
ThisWorkbook.SaveAs Filename:=ThisWorkbook.FullName, accessMode:=xlShared
End If
Application.DisplayAlerts = True
End Sub
Sub DéPartager()
On Error Resume Next
Application.DisplayAlerts = False
MsgBox ("passe en mode exclusive acces :")
ThisWorkbook.ExclusiveAccess ' C'EST A CE MOMENT QUE L'INSTANCE REND LA MAIN EXCLUSIVE SUR LE FICHIER ET DECONNECTE LES AUTRES USERS
Application.DisplayAlerts = True
End Sub
Sub Protéger()
On Error Resume Next
' Protection automatique de toutes les feuilles d'un classeur
Dim nombre As Integer
'nombre = ActiveWorkbook.Sheets.Count
nombre = ThisWorkbook.Sheets.Count
Application.ScreenUpdating = False
Dim Start As Integer
Dim Constante As ConstantClass
Set Constante = NewConstante()
If (CInt(GetExcelNameDefinitionData(Constante.ConsultationFileOnly, ThisWorkbook, Parametersheet.ParametersWorkbook)) = 1) Then
Start = 2
Else
Start = 1
End If
For i = Start To nombre
ThisWorkbook.Worksheets(i).Protect Password:="parameterlock", UserInterfaceOnly:=True
Next i
End Sub
Sub DéProtéger()
On Error Resume Next
Dim nombre As Integer
nombre = ThisWorkbook.Sheets.Count
Application.ScreenUpdating = False
For i = 1 To nombre
ThisWorkbook.Worksheets(i).Unprotect Password:="parameterlock"
Next i
End Sub |
Partager