Private Sub GetMacrosText()
'Put these two lines in the declarations section of the module
'Public iMarcoCount As Integer
'Public MacroText() As String
On Error GoTo Err_ExportMacor2
Dim db As Database
Dim c As Container
Dim d As Document
Dim k As Integer
Dim sTemp As String
Set db = CurrentDb()
iMarcoCount = CurrentProject.AllMacros.Count
ReDim MacroText(iMarcoCount) 'public string array
'loop through the marcos one at a time
'the ExportMacro function returns the text of the macro commands
'store it in a Public Array
Set c = db.Containers("Scripts")
For Each d In c.Documents
sTemp = ExportMacro(d.Name)
MacroText(k) = sTemp
k = k + 1
Next
Set db = Nothing
Set c = Nothing
Exit Sub
Err_ExportMacor2:
MsgBox Err.Number & " - " & Err.Description, vbInformation
Exit Sub
End Sub
Private Function ExportMacro(sMacroName As String) As String
On Error GoTo Err_ExportMacor
Dim iFreeFile As Integer
Dim sTemp As String
Dim sExportLocation As String
sExportLocation = "u:\"
'save the macro as a text file
Application.SaveAsText acMacro, sMacroName, sExportLocation & "Macro_" & sMacroName & ".txt"
'open the file and read in the contents
iFreeFile = FreeFile
Open sExportLocation & "Macro_" & sMacroName & ".txt" For Input As iFreeFile
sTemp = Input(LOF(iFreeFile), #iFreeFile)
Close iFreeFile
'delete the file
Kill sExportLocation & "Macro_" & sMacroName & ".txt"
'pass back the text
ExportMacro = sTemp
Exit Function
Err_ExportMacor:
MsgBox Err.Number & " - " & Err.Description, vbInformation
Exit Function
End Function