2013-10-03 89 views
1

有誰知道如何停止刷新查詢表來不斷刷新,只刷新一次。他不斷刷新,正在讓我的Excel電子表格運行緩慢。如何不刷新backgroundQuery vba

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 

回答

3

改變這一行:

.BackgroundQuery = True 

到:

.BackgroundQuery = False 
+0

Woops。我絕對誤解了這個問題:) +1爲最佳答案。我的工作很有用,但不會這樣做。 – enderland

+0

@enderland,我討厭它發生的時候:)。但至少我們有兩個笑臉gravatars。 –

+0

謝謝@DougGlancy它的工作!謝謝 :) – Abi

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.CalculationxlCalculationManual大的操作之前,然後將其設置爲xlCalculationAutomatic在完成後。