【发布时间】:2019-03-25 14:55:16
【问题描述】:
我想知道 Access VBA 是否可以列出当前 Access 实例中所有打开的文档选项卡。我有可以检查每个 Access 对象并报告它是否已加载的代码。它很快,但感觉像是一种倒退的方法。它也无法列出未保存的对象,例如新查询。此外,我无法分辨哪些对象正在显示选项卡。弹出窗口没有选项卡。
是否有可以列出所有选项卡式文档的 VBA 例程?
Public Sub ListAllOpenObjects()
' This will list all open Access objects. It will not list
' objects that are new that have not be saved, like Query1.
Dim aob As AccessObject
With CurrentData
' "Tables"
For Each aob In .AllTables
If aob.IsLoaded Then
Debug.Print aob.name
End If
Next aob
' "Queries"
For Each aob In .AllQueries
If aob.IsLoaded Then
Debug.Print aob.name
End If
Next aob
End With
With CurrentProject
' "Forms"
For Each aob In .AllForms
If aob.IsLoaded Then
Debug.Print aob.name
End If
Next aob
' "Reports"
For Each aob In .AllReports
If aob.IsLoaded Then
Debug.Print aob.name
End If
Next aob
' "Pages"
For Each aob In .AllDataAccessPages
If aob.IsLoaded Then
Debug.Print aob.name
End If
Next aob
' "Macros"
For Each aob In .AllMacros
If aob.IsLoaded Then
Debug.Print aob.name
End If
Next aob
' "Modules"
For Each aob In .AllModules
If aob.IsLoaded Then
Debug.Print aob.name
End If
Next aob
End With
End Sub
【问题讨论】: