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
| Option Compare Database
Option Explicit
'### Variables ###
Public DetVar 'ne sert pas
Public DetVarPublic As Variant
Public NomProjet As Variant
Public Sub SearchCodeModule3(ByVal Quoi As String, tout As Boolean, DeuxFois As Boolean)
'Tout=True recherche dans tout le module, sinon seulement dans la partie Déclaration (pour les variables)
'le 3° argument sert pour enchainer une fois la sub avec "Public" puis avec "Dim" ,tout en conservant les données lors du 2° passage
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim FindWhat As String
Dim SL As Long ' start line
Dim EL As Long ' end line
Dim SC As Long ' start column
Dim EC As Long ' end column
Dim Found As Boolean
Dim i As Integer, h As Long
i = 1
NomProjet = VBE.VBProjects.Item(i).Name
If DeuxFois Then
Else
ReDim DetVarPublic(1 To 4, 1 To 1) As String
DetVarPublic(1, 1) = "Module"
DetVarPublic(2, 1) = "type de variable"
DetVarPublic(3, 1) = "déclaration"
DetVarPublic(4, 1) = "ligne"
End If
Set VBProj = VBE.VBProjects.Item(NomProjet)
For Each VBComp In VBProj.VBComponents
If VBComp.Type <> 2 Then
Set CodeMod = VBComp.CodeModule
FindWhat = Quoi
With CodeMod
SL = 1
If tout Then
EL = .CountOfLines
Else
EL = .CountOfDeclarationLines 'cherche seulement dans la partie Déclaration du module
End If
SC = 1
EC = 255
Found = .Find(Target:=FindWhat, StartLine:=SL, StartColumn:=SC, _
EndLine:=EL, EndColumn:=EC, _
wholeword:=True, MatchCase:=False, patternsearch:=False)
Do Until Found = False
If Left(LTrim(VBComp.CodeModule.Lines(SL, 1)), 1) <> "'" Then 'pour eviter les lignes commentées
' Debug.Print "Found at: Line: " & CStr(SL) & " Column: " & CStr(SC) & " dans le module " & VBComp.Name & " ligne " & VBComp.CodeModule.Lines(SL, 1)
ReDim Preserve DetVarPublic(1 To 4, 1 To UBound(DetVarPublic, 2) + 1)
DetVarPublic(1, UBound(DetVarPublic, 2)) = VBComp.Name
Select Case Left(LTrim(VBComp.CodeModule.Lines(SL, 1)), 3)
Case "Dim"
DetVarPublic(2, UBound(DetVarPublic, 2)) = "Variables niveau module"
Case "Global"
DetVarPublic(2, UBound(DetVarPublic, 2)) = "Public (pour toute l'application)"
Case Else
If Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 8, 5) = "Const" Then DetVarPublic(2, UBound(DetVarPublic, 2)) = "Constantes"
If InStr(1, LTrim(VBComp.CodeModule.Lines(SL, 1)), "Declare Function") > 0 Then DetVarPublic(2, UBound(DetVarPublic, 2)) = "API"
If InStr(1, LTrim(VBComp.CodeModule.Lines(SL, 1)), "Declare Sub") > 0 Then DetVarPublic(2, UBound(DetVarPublic, 2)) = "API"
If Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 8, 4) = "Enum" Then DetVarPublic(2, UBound(DetVarPublic, 2)) = "Enumération"
Select Case Quoi
Case "Public"
'commence à 8 pour Public
If Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 8, 8) <> "Function" And Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 8, 5) <> "Const" _
And Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 8, 7) <> "Declare" And Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 8, 4) <> "Enum" Then
DetVarPublic(2, UBound(DetVarPublic, 2)) = "Public (pour toute l'application)"
End If
Case "Private"
'commence à 9 pour Public
If Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 9, 8) <> "Function" And Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 9, 5) <> "Const" _
And Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 9, 7) <> "Declare" And Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 9, 4) <> "Enum" Then
DetVarPublic(2, UBound(DetVarPublic, 2)) = "Variables niveau module"
End If
Case "Global"
DetVarPublic(2, UBound(DetVarPublic, 2)) = "Public (pour toute l'application)"
End Select
End Select
If Mid(LTrim(VBComp.CodeModule.Lines(SL, 1)), 1, 20) = "Application.TempVars" Then DetVarPublic(2, UBound(DetVarPublic, 2)) = "TempVars"
h = IIf(InStr(1, LTrim(VBComp.CodeModule.Lines(SL, 1)), Chr(39), 1) > 0, InStr(1, LTrim(VBComp.CodeModule.Lines(SL, 1)), Chr(39), 1), Len(LTrim(VBComp.CodeModule.Lines(SL, 1)))) '29/08/17
DetVarPublic(3, UBound(DetVarPublic, 2)) = Left(LTrim(VBComp.CodeModule.Lines(SL, 1)), h)
DetVarPublic(4, UBound(DetVarPublic, 2)) = SL
End If
If tout Then
EL = .CountOfLines
Else
EL = .CountOfDeclarationLines
End If
SC = EC + 1
EC = 255
Found = .Find(Target:=FindWhat, StartLine:=SL, StartColumn:=SC, _
EndLine:=EL, EndColumn:=EC, _
wholeword:=True, MatchCase:=False, patternsearch:=False)
Loop
End With
End If
i = i + 1
Next VBComp
End Sub
Sub Thierry()
' NomProjet = "Gestion pdm" '"C:\*****\*****.accdb"
SearchCodeModule3 "Public", False, False
SearchCodeModule3 "Global", False, True
SearchCodeModule3 "Dim", False, True
SearchCodeModule3 "Private", False, True
SearchCodeModule3 "Application.TempVars.Add", True, True
End Sub |
Partager