I have the class module:
The initialize module
I get an error on
Set QT = LO.QueryTable,
If I remove the LO portion of the code and just do the For Each QT, it loops through without ever getting into the set, it goes to next QT each loop.
Ideally I only want the before and after refresh events to apply to the query table on sheet3. The query is a range from another workbook. This is the last thing holding back my project from completion and will eternally be grateful to whomever can guide me to getting this to work. Thanks
VBA Code:
Option Explicit
Public WithEvents MyQuery As QueryTable
Private Sub MyQuery_AfterRefresh(ByVal Success As Boolean)
If Success Then MsgBox "Query has been refreshed."
End Sub
Private Sub MyQuery_BeforeRefresh(Cancel As Boolean)
If MsgBox("Refresh query?", vbYesNo) = vbNo Then Cancel = True
End Sub
The initialize module
VBA Code:
Sub InitializeQueries()
Dim clsQ As clsQuery
Dim WS As Worksheet
Dim QT As QueryTable
Dim LO As ListObject
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
For Each LO In WS.ListObjects
Set QT = LO.QueryTable
Set clsQ = New clsQuery
Set clsQ.MyQuery = QT
colQueries.Add clsQ
Next LO
Next WS
End Sub
I get an error on
Set QT = LO.QueryTable,
If I remove the LO portion of the code and just do the For Each QT, it loops through without ever getting into the set, it goes to next QT each loop.
Ideally I only want the before and after refresh events to apply to the query table on sheet3. The query is a range from another workbook. This is the last thing holding back my project from completion and will eternally be grateful to whomever can guide me to getting this to work. Thanks