I'm working on a migration project that deals with several Access 2003 DBs which have hundreds of macros defined on each. I would like write a quick console app that will open the Access file and print out each name and actions of all the macros.
(I.E. if i have a macros in an Access file named MyMacros and it's actions are "Run Query 1", "Run Query 2" and "Run Query 3" --- I want to be able to print this information to a file)
How would I go about in doing this? Which libraries do I need?
The AllMacros collection allows us to loop through the names of all macros in a database but unfortunately, there is no collection/object within the Access Object Model that allows us to iterate through Macro actions.
You could possibly use the undocumented "Saveastext" function to dump each macro into a text file. Exporting a single macro using this function would look like this:
'create folder for text files
Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.folderexists(strFolder & "\texttmp") Then
fs.CreateFolder (strFolder & "\texttmp")
'loop through all macros in database and export them to text files
For i = 1 To objAllObjects.Count
If objAllObjects(i).Count > 0 Then
For j = 0 To objAllObjects(i).Count - 1
Set objObjectGroup = objAllObjects(i)
strCurrentObject = objObjectGroup(j).Name
intObjType = objObjectGroup(j).Type
objAccess.SaveAsText intObjType, strCurrentObject, _
strFolder & "texttmp\" & strCurrentObject & intObjType & ".txt"
To run the code, type the following command in the Immediate window: