Sub InsertionCode()
Dim MaStat$, VBC As Object, i&, t$, p%, nom$, j&, t1$, x$, q%, y$
MaStat = "ThisWorkbook.Stat" 'à adapter
For Each VBC In Me.VBProject.VBComponents
With VBC.CodeModule
For i = .CountOfLines To 1 Step -1
t = Trim(.Lines(i, 1))
p = InStr(t, "End Sub")
If p And InStr(Left(t, p), "'") = 0 Then
nom = .ProcOfLine(i, 0)
j = .ProcBodyLine(nom, 0)
t1 = Trim(.Lines(j, 1))
x = "Sub " & nom & "()*"
If t1 Like x Or t1 Like "Public " & x Then
x = MaStat & " """ & VBC.Name & "." & nom & """: "
q = InStr(t, MaStat)
If q Then
y = Mid(t, q, p - q)
t = Replace(t, y, "")
q = InStrRev(y, """")
If x <> y Then Sheets("Macro_utilisée").[A:A] _
.Replace Mid(y, Len(MaStat) + 3, q - Len(MaStat) - 3), VBC.Name & "." & nom
End If
.ReplaceLine i, Replace(t, "End Sub", x & "End Sub")
End If
i = j
End If
Next
End With
Next
End Sub
Sub Stat(NomMacro$)
With Sheets("Macro_utilisée").Range("a" & Rows.Count).End(xlUp)(2)
.Value = NomMacro
.Offset(, 1) = Now
End With
Me.RefreshAll 'pour mettre à jour le TCD
End Sub