PLease can anyone help with the following code?
I get an object error when I run it and I can't see why.
the error message is "Run-time error 1004. Microsoft Excel is refreshing some data. Please try again later"and debug is on BackgroundQuery = True.
Sub RereshQuery()
Max = 10
Query = Worksheets("Setting").Range("Query_Text3").Text
For i = 1 To Max
Application.ActiveWorkbook.Worksheets("Report").Range("G6").Value = i
Sheets("Book").Select
With ActiveWorkbook.Connections("Book").ODBCConnection
.BackgroundQuery = True
.CommandText = Query
.CommandType = xlCmdSql
.Connection = "ODBC;DRIVER=XXXX;"
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
ActiveWorkbook.Connections("Book").Refresh
Next i
End Sub