0

I have a data tab called "Data" in my current workbook. This data comes from due to a SQL script which is connected to my database.

I would like to activate the background refresh via the code below, but I am not succeeding because of the error run time 1004 Error. Is it possible to fix the code below?

Private Sub Workbook_Open()
    
    Sheets("Data").Select
    Range("A1").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    
End Sub
braX
  • 10,905
  • 5
  • 18
  • 32
  • Please read on [How to avoid using Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). The error most likely comes from you not fully qualifying your worksheet/range. Assuming that the code runs from the same workbook and you only have 1 `QueryTable` in `Data` worksheet, try `ThisWorkbook.Sheets("Data").QueryTables(1).Refresh False` – Raymond Wu Aug 16 '21 at 01:36

0 Answers0