Home » excel » excel – How to NOT refresh backgroundQuery vba

excel – How to NOT refresh backgroundQuery vba

Posted by: admin May 14, 2020 Leave a comment

Questions:

Does anyone know how to stop the refresh query table to constantly refreshing and only refresh itself once. he constant refresh, is making my excel spreadsheet run slow.

With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;" & FilePath, _
       Destination:=temp.Range("A1"))
   .Name = "Deloitte_2013_08"
    '    .CommandType = 0
       .FieldNames = True
       .RowNumbers = False
      .FillAdjacentFormulas = False
     .PreserveFormatting = True
    .RefreshOnFileOpen = False
   .BackgroundQuery = True
  .RefreshStyle = xlInsertDeleteCells
 .SavePassword = False
.SaveData = True
        .AdjustColumnWidth = True
  .RefreshPeriod = 0
      .WebSelectionType = xlEntirePage
     .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = True
   .WebConsecutiveDelimitersAsOne = True
  .WebSingleBlockTextImport = False
 .WebDisableDateRecognition = False
.WebDisableRedirections = False

       .Refresh BackgroundQuery:=False

End With
How to&Answers:

Change this line:

.BackgroundQuery = True

to:

.BackgroundQuery = False

Answer:

Use Application.ScreenUpdating to wrap your code.

application.screenupdating = false
With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;" & FilePath, _
       Destination:=temp.Range("A1"))
   .Name = "Deloitte_2013_08"
    '    .CommandType = 0
       .FieldNames = True
       .RowNumbers = False
      .FillAdjacentFormulas = False
     .PreserveFormatting = True
    .RefreshOnFileOpen = False
   .BackgroundQuery = True
  .RefreshStyle = xlInsertDeleteCells
 .SavePassword = False
.SaveData = True
        .AdjustColumnWidth = True
  .RefreshPeriod = 0
      .WebSelectionType = xlEntirePage
     .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = True
   .WebConsecutiveDelimitersAsOne = True
  .WebSingleBlockTextImport = False
 .WebDisableDateRecognition = False
.WebDisableRedirections = False

       .Refresh BackgroundQuery:=False

End With

application.screenupdating = true

You might also be interested in setting Application.Calculation to xlCalculationManual before a large operation and then setting it to xlCalculationAutomatic after you are done.