Hello
I have a class module "Class1"
Public WithEvents Qt As QueryTable
Private Sub qt_AfterRefresh(ByVal Success As Boolean)
' Declare variables.
Dim My_Prompt As String
' Initialize prompt text for message box.
My_Prompt = "Refresh happened"
' Displays message box before refresh (or cancel) occurs.
MsgBox My_Prompt
End Sub
Private Sub Qt_BeforeRefresh(Cancel As Boolean)
' Declare variables.
Dim My_Prompt As String
' Initialize prompt text for message box.
My_Prompt = "Refresh starts"
' Displays message box before refresh (or cancel) occurs.
MsgBox My_Prompt
End Sub
And a normal module, "General":
Sub Initialize_It()
Set X = New Class1
Application.EnableEvents = True
Dim sht As Worksheet
Dim lQT As Long
Dim LO As ListObject
Dim oQT As QueryTable
For Each LO In Sheets(1).ListObjects
If LO.SourceType = 3 Then 'xlSrcQuery
lQT = lQT + 1
Set oQT = LO.QueryTable
MsgBox oQT.WorkbookConnection.Name
Set X.Qt = oQT
End If
Next LO
oQT.Refresh
End Sub
If I run the macro "Initialize_It", the "before refresh" and "after refresh" events are fired, but not if I go to the Sheet1, right click the Querytable and hit "refresh" (which I want to achieve).
What am I doing wrong?
Thanks in advance!