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
| 'A pour but de créer un fichier de sommaire de toutes les procédures des fichiers ouverts
'Necessite la référence :
'Microsoft Visual Basic for Applications Extensibility 5.3
Public Sub SommaireModules()
Dim objVBProject As VBProject
Dim objVBComponent As VBComponent
Dim objCodeModule As CodeModule
Dim lTypeproc As VBIDE.vbext_ProcKind
Dim objTvw As TreeView
Dim objNewNode1 As MSComctlLib.Node
Dim objNewNode2 As MSComctlLib.Node
Dim objNewNode3 As MSComctlLib.Node
Dim objNewNode4 As MSComctlLib.Node
Dim strNomProc As String
Dim strLine As String
Dim lngStartComment As Long
Dim lngStartProc As Long
Dim lngCountComment As Long
Dim i As Long
Dim x As Long
Set objTvw = MonUserform.tvwSommaire
objTvw.Nodes.Clear 'Purge les noeuds existants
For Each objVBProject In Application.VBE.VBProjects 'Boucle pour explorer chaque fichier excel
Set objNewNode1 = objTvw.Nodes.Add 'Création du noeud racine contenant le nom de fichier
objNewNode1.Expanded = True
On Error Resume Next
objNewNode1.Text = objVBProject.Filename
On Error GoTo 0
If objNewNode1.Text = "" Then
objNewNode1.Text = objVBProject.Name
End If
For Each objVBComponent In objVBProject.VBComponents 'Boucle pour chaque Composant du projet VB (Sheets, ThisWorkbook, Userforms, Modules, Modules de classe)
Set objNewNode2 = objTvw.Nodes.Add(objNewNode1, tvwChild) 'Ajout d'un noeud enfant contenant le nom de composant de projet VB
objNewNode2.Expanded = True
objNewNode2.Text = objVBComponent.Name
Set objCodeModule = objVBComponent.CodeModule 'Permet d'accéder au code contenu dans le composant du projet VB
With objCodeModule
i = .CountOfDeclarationLines + 1
Do Until i >= .CountOfLines
strNomProc = .ProcOfLine(i, lTypeproc)
i = i + .ProcCountLines(strNomProc, lTypeproc)
lngStartComment = .ProcStartLine(strNomProc, lTypeproc)
lngStartProc = .ProcBodyLine(strNomProc, lTypeproc)
If lngStartComment = lngStartProc Then
lngCountComment = .ProcCountLines(strNomProc, lTypeproc)
Else
lngCountComment = lngStartProc - lngStartComment
End If
Set objNewNode3 = objTvw.Nodes.Add(objNewNode2, tvwChild) 'Création d'un noeud enfant à chaque procédure (Function, Sub, etc)
objNewNode3.Expanded = False
objNewNode3.Text = strNomProc & " : L " & lngStartProc
For x = 0 To lngCountComment - 1
strLine = .Lines(lngStartComment + x, 1)
If Replace(strLine, " ", "") <> "" Then
Set objNewNode4 = objTvw.Nodes.Add(objNewNode3, tvwChild) 'Création d'un noeud enfant pour chaque ligne de commentaire précédent une procédure
objNewNode4.Expanded = True
objNewNode4.Text = strLine
strLine = ""
End If
Next x
Loop
End With
Next objVBComponent
Next objVBProject
Set objNewNode4 = Nothing
Set objNewNode3 = Nothing
Set objNewNode2 = Nothing
Set objNewNode1 = Nothing
Set objTvw = Nothing
Set objCodeModule = Nothing
Set objVBComponent = Nothing
Set objVBProject = Nothing
End Sub |
Partager