Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/26983053/how-to-call-macro-after-refresh-or-refresh-all-button-pressed/65131241#65131241

https://www.excelandaccess.com/create-beforeafter-query-update-events/

https://stackoverflow.com/a/65131241/5079799

Class: Note: Class Name = clsQuery

Option Explicit

Public WithEvents MyQuery As QueryTable

Private Sub MyQuery_AfterRefresh(ByVal Success As Boolean)
 If Success Then
  Debug.Print "After ReFresh"
 End If
End Sub

Private Sub MyQuery_BeforeRefresh(Cancel As Boolean)
 Debug.Print "Before ReFresh"
End Sub

Module:

Option Explicit
Dim colQueries As New Collection
Sub InitializeQueries()

Dim clsQ As clsQuery
Dim WS As Worksheet
Dim QT As QueryTable

For Each WS In ThisWorkbook.Worksheets
 For Each QT In WS.QueryTables
  Set clsQ = New clsQuery
  Set clsQ.MyQuery = QT
  colQueries.Add clsQ
 Next QT
Next WS

ThisWorkbook.Event:

Private Sub Workbook_Open()
 
 Call InitializeQueries
 
End Sub
  • No labels