在 MS Access 应用程序中访问原始代码

Posted

技术标签:

【中文标题】在 MS Access 应用程序中访问原始代码【英文标题】:Accessing the raw code in an MS Access application 【发布时间】:2009-03-09 15:17:00 【问题描述】:

我一直在尝试查找有关在 MS Access 中访问原始代码的一些信息(我使用的是 v2007,但可能应该适用于所有版本)。

例如,假设我想列出应用程序中每个代码隐藏表单和模块中的所有函数并列出它们的参数。

您将如何实现这一目标?

注意:我当然假设应用程序没有被编译。

【问题讨论】:

【参考方案1】:

您可以将所有代码输出为文本并通过另一个程序运行或将其加载到数据库中,或者您可以编写代码以使用 VBE 访问代码。

   Sub AllCodeToDesktop()
   'The reference for the FileSystemObject Object is Windows Script Host Object Model
   'but it not necessary to add the reference for this procedure.

   Dim fs As Object
   Dim f As Object
   Dim strMod As String
   Dim mdl As Object
   Dim i As Integer

   Set fs = CreateObject("Scripting.FileSystemObject")

   'Set up the file.
   Set f = fs.CreateTextFile(SpFolder(Desktop) & "\" _
       & Replace(CurrentProject.Name, ".", "") & ".txt")

   'For each component in the project ...
   For Each mdl In VBE.ActiveVBProject.VBComponents
       'using the count of lines ...
       i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
       'put the code in a string ...
       If VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.CountOfLines > 0 Then
          strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.Lines(1, i)
       End If
       'and then write it to a file, first marking the start with
       'some equal signs and the component name.
       f.writeline String(15, "=") & vbCrLf & mdl.Name _
           & vbCrLf & String(15, "=") & vbCrLf & strMod
   Next

   'Close eveything
   f.Close
   Set fs = Nothing
End Sub

发件人:http://wiki.lessthandot.com/index.php/Code_and_Code_Windows

【讨论】:

谢谢,我知道我遗漏了一些东西,不记得有一个 VBE 对象。再次感谢:-)【参考方案2】:

是否可以从另一个程序调用 VBE 对象?很抱歉从死里复活,我有新的讨论here

【讨论】:

以上是关于在 MS Access 应用程序中访问原始代码的主要内容,如果未能解决你的问题,请参考以下文章

MS 访问事件加载表单

MS Access FileDialog 过滤器在原始负载上不起作用

MS Access 32 位或 64 位

MS Access驱动程序问题

在 Win7 X64 上使用 Qt 访问 MS Access 数据库

在 VBA 中查找适用于 MS Access 和 MS Excel 的应用程序目录路径