excel - VBA will not Refresh Queries
问题描述
Backstory: I am currently working on a "make-shift" database using excel. I will have one central excel workbook which will house the tables on separate sheets storing data. Other workbooks will interface with this database excel workbook and will input new lines or replace existing lines in the tables by each user interface. The user-interface workbooks will have query tables pulling from the database workbook tables as needed to provide the users with information. I am sure there must be a better way of doing this. Any tips tricks or pointers are much appreciated.
Problem: I have written in my VBA Database Input code to Refresh All queries however it does not update the queries. I have made a separate sub to update queries but when it is called by the Databse Input code it does not.
Sub Refresh_Queries
Dim ActWB as Object
Set ActWB = ThisWorkbook
ActWB.RefreshAll
End Sub
解决方案
Are these actual query objects, or something else, perhaps? Make sure you are acting on the correct type of object. Maybe these are workbook connections. Just making a guess here...
Sub Something()
Dim Connection As Variant
For Each Connection In ActiveWorkbook.Connections
Connection.OLEDBConnection.BackgroundQuery = False
Connection.Refresh
Next Connection
End Sub
Or...
Sub Workbook_RefreshAll()
ActiveWorkbook.RefreshAll
End Sub
I hav seen some weird things in the past, like doing a single refresh doesn't work, but doing it a second time works perfectly fine. See the link below for some additional ideas of what you can do to refresh queries, connections, and the like.
推荐阅读
- python - 将向量 Numpy 与不同的 Datetime 对象进行比较
- mysql - 使用 uuid 作为默认值时如何使用 LAST_INSERT_ID()?
- c# - LINQ to SQL:按值将单个记录存储在内存中(SubmitChanges 后不应更改)
- sql - 在 MariaDB 中将列条目拆分为多行和多列
- swiftui - 如何更改 navigationBarItem 颜色
- javascript - 在 HTML 文件的脚本标记 (JS) 中使用作为上下文传递的 django 变量
- batch-file - 如果批量为NULL,如何为变量赋值?
- java - 使用内部选择更新 - oracle
- azure-data-factory - 在 Azure 数据工厂(数据流)中筛选源数据以获取最新值
- iframe - 惰性尺寸不显示视频