此代碼將DataMacro元數據導出到一個XML文檔(Source):
Sub DocumentDataMacros()
'loop through all tables with data macros
'write data macros to external files
'open folder with files when done
' click HERE
' press F5 to Run!
' Crystal
' April 2010
On Error GoTo Proc_Err
' declare variables
Dim db As DAO.Database _
, r As DAO.Recordset
Dim sPath As String _
, sPathFile As String _
, s As String
' assign variables
Set db = CurrentDb
sPath = CurrentProject.Path & "\"
s = "SELECT [Name] FROM MSysObjects WHERE Not IsNull(LvExtra) and Type =1"
Set r = db.OpenRecordset(s, dbOpenSnapshot)
' loop through all records until the end
Do While Not r.EOF
sPathFile = sPath & r!Name & "_DataMacros.xml"
'Big thanks to Wayne Phillips for figuring out how to do this!
SaveAsText acTableDataMacro, r!Name, sPathFile
'have not tested SaveAsAXL -- please share information if you do
r.MoveNext
Loop
' give user a message
MsgBox "Done documenting data macros for " & r.RecordCount & " tables ", , "Done"
Application.FollowHyperlink CurrentProject.Path
Proc_Exit:
' close and release object variables
If Not r Is Nothing Then
r.Close
Set r = Nothing
End If
Set db = Nothing
Exit Sub
Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " DocumentDataMacros"
Resume Proc_Exit
Resume
End Sub
編輯:戈德指出,你想反對標準宏DataMacros。我發現了一些代碼並進行了測試(它的工作原理)here
我測試了頂級函數,當您遵循該鏈接時,它保存了XML文檔中每個表的關於表宏的信息。它很好地工作,支持寫它的人。
您是否嘗試使用該方法列出數據宏(Access 2010中的新增功能),而不是「常規」宏?我做了,它不適合我...... – 2013-04-27 07:40:45
@GordThompson其實,我只是用標準的宏來試用它。我剛剛發現了一些數據宏的代碼,將用我發現的內容更新我的答案。 – Scotch 2013-04-27 08:06:00
@Scotch:重寫你的答案,只是解決數據宏(這是問題,而不是普通的宏),我將它標記爲答案。對於未來的讀者來說,讓內容出錯是件容易混淆的事,但鏈接是正確的 – 2013-04-29 12:38:59