how do you view macro code in access?

前端 未结 5 1275
清酒与你
清酒与你 2021-02-05 04:52

I have a Microsoft Access database and there is a macro there. How do I view the code of the macro?

5条回答
  •  星月不相逢
    2021-02-05 05:20

    You can try the following VBA code to export Macro contents directly without converting them to VBA first. Unlike Tables, Forms, Reports, and Modules, the Macros are in a container called Scripts. But they are there and can be exported and imported using SaveAsText and LoadFromText

    Option Compare Database
    
    Option Explicit
    
    Public Sub ExportDatabaseObjects()
    On Error GoTo Err_ExportDatabaseObjects
    
        Dim db As Database
        Dim d As Document
        Dim c As Container
        Dim sExportLocation As String
    
        Set db = CurrentDb()
    
        sExportLocation = "C:\SomeFolder\"
        Set c = db.Containers("Scripts")
        For Each d In c.Documents
            Application.SaveAsText acMacro, d.Name, sExportLocation & "Macro_" & d.Name & ".txt"
        Next d
    

    An alternative object to use is as follows:

      For Each obj In Access.Application.CurrentProject.AllMacros
        Access.Application.SaveAsText acMacro, obj.Name, strFilePath & "\Macro_" & obj.Name & ".txt"
      Next
    

提交回复
热议问题