Not long ago, I had gotten a solution to allow for a Query Table to be refreshed. Since then, I have found a problem that needs to be fixed. Here is the code I have right now:

Module Code:
Option Explicit

Dim DataTable As New Class1

Sub Auto_Open()

ActiveSheet.Range("B2").Select
Set DataTable.qt = ThisWorkbook.Sheets("Data").QueryTables(1)
End Sub

Sub AutoSort()
Dim WQ As Range
Dim wd As Worksheet

Set wd = ActiveWorkbook.Sheets("Data")
Set WQ = wd.Range("BP2:Bw40")
WQ.Sort Key1:=wd.Range("BP2"), Order1:=xlAscending, Header:=xlYes


End Sub
Class Code:
Option Explicit

Public WithEvents qt As QueryTable

Private Sub qt_AfterRefresh(ByVal Success As Boolean)

If Success = True Then

Call Module1.AutoSort

End If

End Sub
My problem is with the 'Set wd = ActiveWorkbook.Sheets("Data")' part of the code. As long as the workbook Runescape Guide is active, nothing wrong happens. However, when I am using another Office Document at time of Query Refresh, it stops working. Is there a code that can be added to let macro run while the workbook is inactive?