Вы могли бы использовать что-то подобное, но оно не будет работать без присмотра, потому что вы, вероятно, получите все виды проблем с паролями и тому подобное.
Перепишите
Это будет искать форму и сообщать код и модули, включая модули класса, но не будет искать комментарии.
Sub SearchAllCode()
Dim ap As New Access.Application
Dim sfile As String, afind As Variant
Dim mdlname As String, mdl As Object
Dim prcname As String
Dim lsline As Long, lscol As Long
Dim leline As Long, lecol As Long
Dim sline As String, r As Long
Dim i, j
ap.Visible = True
afind = Split("msgbox,chair,ombo,Visible", ",")
sfile = Dir("Z:\Docs\*.accdb")
Do While sfile <> vbNullString
ap.OpenCurrentDatabase "Z:\Docs\" & sfile, False, "pass"
For i = 1 To ap.VBE.ActiveVBProject.VBComponents.Count
Set mdl = ap.VBE.ActiveVBProject.VBComponents(i).CodeModule
For j = 0 To UBound(afind)
leline = mdl.CountOfLines
''object.Find(target, startline, startcol, endline, endcol
''[, wholeword] [, matchcase] [, patternsearch]) As Boolean
''The default is false for the three optional parameters.
''Finds first occurrence only
If mdl.Find(afind(j), lsline, lscol, leline, lecol) Then
sline = mdl.Lines(lsline, Abs(leline - lsline) + 1)
prcname = mdl.ProcOfLine(lsline, r)
Debug.Print mdl.Name
Debug.Print prcname
Debug.Print lsline
Debug.Print sline
End If
Next
Next
ap.CloseCurrentDatabase
sfile = Dir
Loop
ap.Quit
End Sub
Вот альтернативный поиск, но он не дает вам возможности манипулировать кодом, как только строка найдена.
Sub AlternativeSearch()
Dim ap As New Access.Application
Dim sfile As String, afind As Variant
Dim mdl As Object
Dim modtext As String, modarray As Variant
Dim leline As Long
Dim i, j, k
ap.Visible = True
afind = Split("msgbox,chair,ombo,Visible", ",")
sfile = Dir("Z:\Docs\*.accdb")
Do While sfile <> vbNullString
ap.OpenCurrentDatabase "Z:\Docs\" & sfile, False, "pass"
For i = 1 To ap.VBE.ActiveVBProject.VBComponents.Count
Set mdl = ap.VBE.ActiveVBProject.VBComponents(i).codemodule 'ap.Modules(mdlname)
leline = mdl.CountOfLines
modtext = mdl.Lines(1, leline)
For j = 0 To UBound(afind)
If InStr(modtext, afind(j)) > 0 Then
Debug.Print "****" & afind(j) & " found in " & mdl.Name
modarray = Split(modtext, vbCrLf)
For k = 0 To UBound(modarray)
If InStr(modarray(k), afind(j)) > 0 Then
Debug.Print k
Debug.Print modarray(k)
End If
Next
End If
Next
Next
ap.CloseCurrentDatabase
sfile = Dir
Loop
ap.Quit
End Sub