Access データベース ファイル内のコード モジュールの検索に関心がある場合は、VBE オブジェクト モデルを使用できます。ActiveVBProject
このサンプルは、現在のデータベースのすべてのモジュールで単語を検索します。データベースに複数の VBProject が含まれている場合は、VBProjects コレクションを列挙し、プロジェクトを一度に 1 つずつ名前で検索できます。
For Each objComponent In Application.VBE.VBProjects(ProjName).VBComponents
または、プロジェクトを名前ではなく番号で参照したい場合は、番号が 0 ではなく 1 から始まることに注意してください。
Public Sub findWordInModules(ByVal pSearchWord As String)
'Dim objComponent As VBComponent
' VBComponent requires reference to Microsoft Visual Basic
' for Applications Extensibility; use late binding instead:
Dim objComponent As Object
Dim strMessage As String
Dim strModuleList As String
strModuleList = vbNullString
For Each objComponent In Application.VBE.ActiveVBProject.VBComponents
If objComponent.CodeModule.Find(pSearchWord, 1, 1, -1, -1) = True Then
strModuleList = strModuleList & "; " & objComponent.Name
End If
Next objComponent
strMessage = "Text '" & pSearchWord & "' found in "
If Len(strModuleList) > 0 Then
strMessage = strMessage & "modules: " & Mid(strModuleList, 3)
Else
strMessage = strMessage & "no modules"
End If
Debug.Print strMessage
End Sub
Find
その方法の Access ヘルプ トピックを確認します。私が使用したものとは異なるオプションを好むかもしれません。
複数の db ファイルをターゲットにして、それぞれのモジュールを検索する場合は、メソッドを使用してこれを自動化できますOpenDatabase
。その部分の詳細はお任せします。