要查看数据库是否包含宏,您可以使用 DAO 中记录的方法。这是来自https://msdn.microsoft.com/en-us/library/office/ff191764.aspx的修改示例:
Sub ContainerObjectX()
Dim dbsNorthwind As Database
Dim ctrLoop As Container
Dim prpLoop As Property
Dim docItem As Document
' Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set dbsNorthwind = CurrentDb
With dbsNorthwind
' Enumerate Containers collection.
For Each ctrLoop In .Containers
Debug.Print "Properties of " & ctrLoop.Name _
& " container"
' Enumerate Properties collection of each
' Container object.
For Each prpLoop In ctrLoop.Properties
Debug.Print " " & prpLoop.Name _
& " = "; prpLoop
Next prpLoop
For Each docItem In ctrLoop.Documents
Debug.Print " docItem.Name = "; docItem.Name
Next docItem
Next ctrLoop
.Close
End With
End Sub
因此,您只需要检查“脚本”容器下的文档。
我的原始答案:我认为您可以使用 ExportXML 和 ImportXML 功能更强大,并且能够导出和导入所有访问对象。例子:
ExportXML acExportTable, "tblMain", CM_GetDBPath() & "AccessFunc_Tbl.xml" _
, CM_GetDBPath() & "AccessFunc_TblShema.xml", CM_GetDBPath() & "AccessFunc_Tbl.xsl" _
, "Images", , acEmbedSchema
....
ImportXML CM_GetDBPath() & "AccessFunc_Tbl.xml", acAppendData
完整的例子在这里:http: //5codelines.net/wp-content/uploads/xml_1_sampe.rar
您也可以使用 ADODB 库。
Public Function EportTblToXml(ByVal imTblFrom As String _
, ByVal imFileTo As String)
Dim rstData As ADODB.Recordset
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Set rstData = New ADODB.Recordset
rstData.Open "SELECT * FROM " & imTblFrom, cnn _
, adOpenKeyset, adLockOptimistic
Call SaveRstToXml(rstData, imFileTo)
rstData.Close
End Function
Public Function LoadXmlToRst(ByVal stFileName As String) As ADODB.Recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open stFileName
Set LoadXmlToRst = rst
End Function