seniorjerry
New Member
- Joined
- Jan 20, 2023
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
Hey I have an excel file that has a lot of connections and have a VBA program that gets all connections in the workbook and updates them. I have been able to successfully set up the AfterRefresh() event to figure out whether a query has been updated properly or not however I am unsure of if their is a way to know which one triggered the event unless I do them one at a time. Is their a way to get the query / query name in the AfterRefresh() event without having to run one query at a time?
Here is the current code that runs one query at a time. If I run multiple at once I could run into the issue of them finishing out of order and then not knowing which one just finished
Please let me know if you need any more information that I can provide. Thanks
Here is the current code that runs one query at a time. If I run multiple at once I could run into the issue of them finishing out of order and then not knowing which one just finished
Please let me know if you need any more information that I can provide. Thanks
VBA Code:
Option Explicit
Private WithEvents table As Excel.QueryTable
Private currentIndex As Long
Private tables As Variant
Private Sub table_AfterRefresh(ByVal Success As Boolean)
If Success Then
currentIndex = currentIndex + 1
'Then move on to next query
Else
' Retry updating the query once
End If
If Success And currentIndex <= UBound(tables) Then
Set table = tables(currentIndex)
table.Refresh
End If
End Sub
Public Sub UpdateTables()
tables = 'List of all queries
currentIndex = 0
Set table = tables(currentIndex)
table.Refresh
End Sub