how do you view macro code in access?

前端 未结 5 1267
清酒与你
清酒与你 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:03

    This did the trick for me: I was able to find which macro called a particular query. Incidentally, the reason someone who does know how to code in VBA would want to write something like this is when they've inherited something macro-ish written by someone who doesn't know how to code in VBA.

    Function utlFindQueryInMacro
           ( strMacroNameLike As String
           , strQueryName As String
           ) As String 
        ' (c) 2012 Doug Den Hoed 
        ' NOTE: requires reference to Microsoft Scripting Library
        Dim varItem As Variant
        Dim strMacroName As String
        Dim oFSO As New FileSystemObject
        Dim oFS   
        Dim strFileContents As String
        Dim strMacroNames As String
        For Each varItem In CurrentProject.AllMacros
        strMacroName = varItem.Name
        If Len(strMacroName) = 0 _
        Or InStr(strMacroName, strMacroNameLike) > 0 Then
            'Debug.Print "*** MACRO *** "; strMacroName
            Application.SaveAsText acMacro, strMacroName, "c:\temp.txt"
            Set oFS = oFSO.OpenTextFile("c:\temp.txt")
            strFileContents = ""
            Do Until oFS.AtEndOfStream
                strFileContents = strFileContents & oFS.ReadLine
            Loop
            Set oFS = Nothing
            Set oFSO = Nothing
            Kill "c:\temp.txt"
            'Debug.Print strFileContents
            If InStr(strFileContents, strQueryName)     0 Then
                strMacroNames = strMacroNames & strMacroName & ", "
            End If
        End If
        Next varItem
        MsgBox strMacroNames
        utlFindQueryInMacro = strMacroNames
     End Function
    

提交回复
热议问题