1

有谁知道如何停止刷新查询表以不断刷新并且只刷新一次。他不断刷新,使我的 Excel 电子表格运行缓慢。

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
4

2 回答 2

3

更改此行:

.BackgroundQuery = True

至:

.BackgroundQuery = False
于 2013-10-03T15:53:41.920 回答
0

使用Application.ScreenUpdating来包装您的代码。

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

您可能也有兴趣在大型操作之前将Application.Calculation设置为,然后在完成后将其设置为。xlCalculationManualxlCalculationAutomatic

于 2013-10-03T15:34:03.663 回答