vba - VBA 列出 MS Access 中所有打开的对象
问题描述
我想知道 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
解决方案
表单和报告有一个快捷方式,因为Application.Forms包含所有打开的表单,Application.Reports包含打开的报告(无论它们是弹出窗口还是不可见)。
由于用户不应该能够打开表或查询,这在生产中就足够了。
如果您在开发过程中需要该信息,则必须循环相应的集合并检查每个集合的IsLoaded
.
作为替代方案,您应该能够通过它们的句柄检测打开的选项卡,但这需要广泛使用(和知识)WinAPI 函数,如FindWindow
和GetClassName
。这可用于提高您的 WinAPI 技能,但并不比循环集合更优雅。
推荐阅读
- c# - AppBarButton 在 UWP C# 项目中更改图标和标签后失去功能
- c - 如何停止用替换字符替换字符??
- bash - 如何按时间而不是按大小对 shell 脚本输入进行分块?
- javascript - 多个 Ace Editor 内容仅返回一行
- swift - 快速读写firestore文档和集合
- c# - ASP.NET Core - 有什么理由不使用带有依赖注入的参数对象?
- ios - 找不到框架 RealmSwift
- php - WordPress 中的 PHP DOM - 替换和添加属性
- sql - 如何在oracle中合并特定的单元格表数据
- java - 加载和编辑先前填写的特定数据