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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| Option Compare Database
Option Explicit
'Source: https://www.developpez.net/forums/d670103/logiciels/microsoft-office/access/contribuez/lister-fonctions-procedures-d-base-access/
'Liste tous les Module, Sub et Function dans le projet en cours, dans la table T_Liste_Procedures
'La table peut etre crée avec la Sub CreateTable (voir ci-dessous)
'Pour exécuter: ? Liste_Procedures_Fonctions_VBA_ThisDatabase()
'ou mettre le curseur dans la procédure et Exécuter
'Les données de la table T_Liste_Procedures peuvent etre mises facilement dans Excel (copier coller)
Public Function Liste_Procedures_Fonctions_VBA_ThisDatabase() As Boolean
Dim i As Integer, k As Integer
Dim cible As String, prmModule As String, prmComment As String
Dim prmType As String, prmName As String, prmParam As String, prmReturn As String, prmPath As String, prmScope As String
'On Error GoTo fin
DoCmd.RunSQL "delete from T_LISTE_PROCEDURES"
For i = 1 To VBE.ActiveVBProject.VBComponents.Count
With VBE.ActiveVBProject.VBComponents.Item(i).CodeModule
prmModule = VBE.ActiveVBProject.VBComponents.Item(i).CodeModule
For k = 1 To .CountOfLines
cible = .Lines(k, 1)
If Left(cible, 1) <> "'" Then
If InStr(1, cible, "Function ") > 0 And InStr(1, cible, "Function ") < 15 Then 'le 10 évite les cibles parasites Function
prmComment = RecupComment(cible)
prmType = "Function"
prmName = Trim(RecupererTexteEntreBornes(cible, "Function", "("))
prmParam = RecupererTexteEntreBornes(cible, "(", ")")
prmReturn = RecupererTexteEntreBornes(cible, ") As", "")
prmScope = IIf(InStr(1, cible, "Private") <> 0, "Private", IIf(InStr(1, cible, "Public") <> 0, "Public", ""))
CurrentDb.Execute "INSERT INTO T_LISTE_PROCEDURES (path,module,scope,comment,category,procname,param,return)" _
& "VALUES ('" & "CurrentProject" & "','" & prmModule & "','" & prmScope & "','" & prmComment & "','" & prmType & "','" & prmName & "' ,'" & prmParam & "','" & prmReturn & "');"
End If
If InStr(1, cible, "Sub ") > 0 And InStr(1, cible, "Sub ") < 15 Then ''le 10 évite les cibles parasites Sub
prmComment = RecupComment(cible)
prmType = "Sub"
prmName = Trim(RecupererTexteEntreBornes(cible, prmType, "("))
prmParam = RecupererTexteEntreBornes(cible, "(", ")")
prmScope = IIf(InStr(1, cible, "Private") <> 0, "Private", IIf(InStr(1, cible, "Public") <> 0, "Public", ""))
CurrentDb.Execute "INSERT INTO T_LISTE_PROCEDURES (PATH,module,scope,comment,category,procname,param) " _
& "VALUES ('" & "CurrentProject" & "','" & prmModule & "','" & prmScope & "','" & prmComment & "','" & prmType & "','" & prmName & "','" & prmParam & "')"
End If
prmParam = ""
End If
Next k
End With
Next i
'CurrentDb.Execute "UPDATE T_LISTE_PROCEDURES SET PARAM = '' WHERE Left(PARAM,1)=')'"
Liste_Procedures_Fonctions_VBA_ThisDatabase = True
Exit Function
fin:
Liste_Procedures_Fonctions_VBA_ThisDatabase = False
Resume Next
End Function
'Utilise table T_LISTE_PROCEDURES
'? Liste_Procedures_Fonctions_VBA("D:\_AccessMoi\Harmonie173.accdb")
Public Function Liste_Procedures_Fonctions_VBA(pathbase As String) As Boolean 'comment
Dim strSQL As String
Dim Accmodule As module
Dim i As Integer, k As Integer
Dim oDb As Database, oAccess As New Access.Application
Dim cible As String, prmModule As String, prmComment As String
Dim prmType As String, prmName As String, prmParam As String, prmReturn As String, prmPath As String, prmScope As String
'On Error GoTo fin
DoCmd.RunSQL "delete from T_LISTE_PROCEDURES"
With oAccess
.Visible = False
.OpenCurrentDatabase (pathbase)
Set oDb = .CurrentDb
End With
For i = 1 To oAccess.VBE.VBProjects(1).VBComponents.Count
With oAccess.VBE.VBProjects(1).VBComponents.Item(i).CodeModule
prmModule = oAccess.VBE.VBProjects(1).VBComponents.Item(i).CodeModule
For k = 1 To .CountOfLines
cible = .Lines(k, 1)
If Left(cible, 1) <> "'" Then
If InStr(1, cible, "Function ") > 0 And InStr(1, cible, "Function ") < 15 Then 'le 10 évite la cible " Currentdb.execute etc...
prmComment = RecupComment(cible)
prmType = "Function"
prmName = Trim(RecupererTexteEntreBornes(cible, "Function", "("))
prmParam = RecupererTexteEntreBornes(cible, "(", ")")
prmReturn = RecupererTexteEntreBornes(cible, ") As", "")
prmScope = IIf(InStr(1, cible, "Private") <> 0, "Private", IIf(InStr(1, cible, "Public") <> 0, "Public", ""))
CurrentDb.Execute "INSERT INTO T_LISTE_PROCEDURES (PATH,module,scope,comment,category,procname,param,return)" _
& "VALUES ('" & pathbase & "','" & prmModule & "','" & prmScope & "','" & prmComment & "','" & prmType & "','" & prmName & "','" & prmParam & "','" & prmReturn & "');"
End If
If InStr(1, cible, "Sub ") > 0 And InStr(1, cible, "Sub ") < 15 Then 'le 10 évite la cible " Currentdb.execute etc...
prmComment = RecupComment(cible)
prmType = "Sub"
prmName = Trim(RecupererTexteEntreBornes(cible, "Sub", "("))
prmParam = RecupererTexteEntreBornes(cible, "(", ")")
prmScope = IIf(InStr(1, cible, "Private") <> 0, "Private", IIf(InStr(1, cible, "Public") <> 0, "Public", ""))
CurrentDb.Execute "INSERT INTO T_LISTE_PROCEDURES (PATH,module,scope,comment,category,procname,param)" _
& "VALUES ('" & pathbase & "','" & prmModule & "','" & prmScope & "','" & prmComment & "','" & prmType & "','" & prmName & "','" & prmParam & "');"
End If
End If
Next k
End With
Next i
'CurrentDb.Execute "UPDATE T_LISTE_PROCEDURES SET PARAM = '' WHERE Left(PARAM,1)=')'"
oDb.Close
oAccess.DoCmd.Close , , acSaveYes
Set oAccess = Nothing
Set oDb = Nothing
Liste_Procedures_Fonctions_VBA = True
Exit Function
fin:
Liste_Procedures_Fonctions_VBA = False
Resume Next
End Function
'Fonction utilisée pour récuperer un texte compris entre deux autres
Public Function RecupererTexteEntreBornes(texte As String, textedebut As String, textefin As String) As String
Dim result As String, debut As Integer, fin As Integer, v As Variant
v = Split(texte, "'")
If UBound(v) > 0 Then texte = v(0) 'pour éliminer la partie commentaire
debut = InStr(1, texte, textedebut)
fin = InStr(debut + Len(textedebut), texte, textefin)
If debut > 0 Then
If textedebut = "Function" Or textedebut = "Sub" Then result = Mid(texte, debut + Len(textedebut) + 1, fin - debut - Len(textedebut) - 1) 'name
If textedebut = "(" Then result = Mid(texte, debut + 1, fin - debut - 1) 'param
If textedebut = ") as" Then result = Mid(texte, fin + 1, Len(texte) - fin) 'return
End If
RecupererTexteEntreBornes = result
End Function
Public Function RecupComment(cible As String) As String
Dim v, i As Integer, txt As String
v = Split(cible, "'")
If UBound(v) >= 1 Then 'un commentaire existe après Function ou Sub
v(0) = "" 'enlever le texte avant '
txt = Join(v, " ") 'reconstituer le commentaire, mais remplacer ' par Espace pour éviter l'erreur avec CurrentDb.Execute "INSERT INTO ...
RecupComment = Right(txt, Len(txt) - 1) 'pour enlever le caractère du début
End If
End Function
'https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/create-table-statement-microsoft-access-sql
Public Sub CreateTable() 'crée table' T_Liste_Procedures
CurrentDb.Execute "CREATE TABLE T_Liste_Procedures " _
& "(Path MEMO, Module CHAR, Scope CHAR, Category MEMO,Nom MEMO, Param MEMO, Return MEMO, Commentaire MEMO);"
RefreshDatabaseWindow
'les données de la table peuvent etre exportées dans un fichier Excel
End Sub
Public Sub Test_RecupererTexteEntreBornes()
Dim cible As String
cible = "Private Function Liste_Procedures_Fonctions_VBA_ThisDatabase(param) as Boolean"
Debug.Print "name", RecupererTexteEntreBornes(cible, "Function", "(")
Debug.Print "param", RecupererTexteEntreBornes(cible, "(", ")")
Debug.Print "return", RecupererTexteEntreBornes(cible, ") as", "")
End Sub |
Partager