Codes VBA Suivi des modifications
Dans le processus de suivi de la traçabilité, il est nécessaire de faire un suivi des changements effectués sur les documents électroniques.
Dans le cas présent, il s’agit des données entrées dans un fichier Excel. Ce code permet en de copier les modification effectuées dans les cases d’un onglet dans un autre onglet nommé « log »
Toute modification effectuée dans l’onglet en question est reportée dans l’onglet log avec les informations suivantes:
Qui l’à fait / A quelle date / information préalablement dans la case / nouvelle information inscrite.
L’onglet log ne peut pas être protégé par mot de passe, mais peut être caché.
Voici le code:
Dim PreviousValue
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Value <> PreviousValue Then
Sheets(« log »).Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & » changed cell » & Target.Address _
& » from » & PreviousValue & » to » & Target.Value
Sheets(« log »).Cells(65000, 1).End(xlUp).Offset(0, 1).Value = Now
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value
End Sub
SOURCE : https://www.excelforum.com/excel-programming-vba-macros/812576-problem-macro.html
VBA : CODE POUR ENREGISTRER LES MODIFICATION FAITES DANS UN ONGLET EXCEL — FONCTIONNEL.
Un ongle nommé « log » doit être crée. C’est dans cet onglet que seront enregistrées les modifications.
Ce code marche, mais juste qu’il n’affiche pas l’information précédente qui a été modifiée.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value <> PreviousValue Then
Sheets(« log »).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Value = Environ(« Username ») & « changed cell » & _
Target.Address & » from » & PreviousValue & » to » & Target.Value & » ( » & Now & « ) «
End If
End Sub
UN CODE LUI AFFICHE DIRECTEMENT EN NOTE – FONCTIONNEL.
Le problème, met en note toutes les insertions et les modifications. Ennuyeux. Pour que ca se fasse discrètement (sans voire les notes ou le signe indiquant l’annotation) aller dans:
Ficher/Option/Options avancées
Affichage
Pour les cellules avec commentaires
Cocher : Afficher aucun commentaire.
Private Sub Worksheet_Change(ByVal Target As Range)
‘Updateby Extendoffice
Const xRg As String = « A1:Z1000 »
Dim strOld As String
Dim strNew As String
Dim strCmt As String
Dim xLen As Long
With Target(1)
If Intersect(.Cells, Range(xRg)) Is Nothing Then Exit Sub
strNew = .Text
Application.EnableEvents = False
Application.Undo
strOld = .Text
.Value = strNew
Application.EnableEvents = True
strCmt = « Edit: » & Format$(Now, « dd Mmm YYYY hh:nn:ss ») & » by » & _
Application.UserName & Chr(10) & « Previous Text :- » & strOld
If Target(1).Comment Is Nothing Then
.AddComment
Else
xLen = Len(.Comment.Shape.TextFrame.Characters.Text)
End If
With .Comment.Shape.TextFrame
.AutoSize = True
.Characters(Start:=xLen + 1).Insert IIf(xLen, vbLf, « ») & strCmt
End With
End With
End Sub
SOURCE: https://fr.extendoffice.com/documents/excel/3961-excel-track-changes-without-sharing-workbook.html>