Accessing the raw code in an MS Access application

2019-07-20 18:40发布

I've been trying to find some information about getting access to the raw code in MS Access (I use v2007 but should probably apply to all versions).

Say for instance that I'd like to list all functions in every code-behind form and module in the application and list their parameters.

How would you achieve this?

Note: I'm of course assuming that the application is not compiled.

标签: ms-access com
2条回答
Deceive 欺骗
2楼-- · 2019-07-20 19:06

You can output all the code to text and run it though another program or load it into a database, or you can write code to access the code using 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

From: http://wiki.lessthandot.com/index.php/Code_and_Code_Windows

查看更多
姐就是有狂的资本
3楼-- · 2019-07-20 19:14

Is it possible to call the VBE object from another program? Sorry to raise this from the dead, I have the new discussion here

查看更多
登录 后发表回答