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

时间:2009-03-09 15:17:00

标签: ms-access com

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

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

你将如何实现这一目标?

注意:我当然假设应用程序未编译。

2 个答案:

答案 0 :(得分:4)

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

   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

答案 1 :(得分:1)

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