Forum Discussion
MichaelJSchulz
May 11, 2022Copper Contributor
Run VBA after Refresh All with multiple tables
I want to have a block of VBA code run after all the tables in the workbook have refreshed: User clicks the Refresh All button which causes All tables in the workbook to be refreshed four tables,...
May 11, 2022
MichaelJSchulz Try replacing
Private Sub Workbook_Open() Set QT = Sheet1.ListObjects(1).QueryTable End Sub
with
Private Sub Workbook_Open()
Dim i as Long
For i = 1 to Sheets.Count Set QT = Sheets(i).ListObjects(1).QueryTable
Next i End Sub
If there are sheets in addition to the 4 sheets that contain the tables,
you may need to use
Private Sub Workbook_Open()
Dim i as Long
For i = 1 to Sheets.Count
If Sheets(i).ListObjects.Count>0 then
Set QT = Sheets(i).ListObjects(1).QueryTable
End if
Next i
End Sub
MichaelJSchulz
May 11, 2022Copper Contributor
Doug_Robbins_Word_MVP
It does not appear to work as we want.
If I correctly understand what is happening by viewing the Locals window, QT holds only one table at a time instead of holding multiple tables.
It does not appear to work as we want.
If I correctly understand what is happening by viewing the Locals window, QT holds only one table at a time instead of holding multiple tables.