2017-05-08 40 views
0

我用宏從htm文件導入數據。到目前爲止,查詢表也工作得很好。然後我把整個文件移動到一個在線文件夾,它不再工作。宏停在最後一行backgroundquery。我認爲它與文件移動到聯機文件夾有關,速度可能不足以導入數據。但我沒有足夠的經驗去理解那裏寫的是什麼。我只是記錄了這個宏。你知道它爲什麼停止工作嗎?查詢表Excel調試導入

With ActiveSheet.QueryTables.Add(Connection:= _ 
    "URL;file:///C:/.../.../..." & Datei & ".htm",  Destination:= _ 
    Range("$A$1")) 
    .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 

回答

0

它停止,因爲它無法加載(.refresh)文件。你檢查過文件的路徑嗎?

否則,問題可能會發生,因爲您已經有一個查詢表,它不能創建/替換舊的查詢表。刪除舊的查詢表並再次運行您的代碼。要刷新現有的查詢表,請使用此子文件:

Sub Refresh() 
Dim qt As QueryTable 
Set qt = Worksheets("Table1").ListObjects(1).QueryTable 

With qt 
    .Refresh 
End With 
End Sub