返回列表 上一主題 發帖

[發問] Excel網頁外部資料匯入失敗之解決(.Refresh BackgroundQuery:=False)

[發問] Excel網頁外部資料匯入失敗之解決(.Refresh BackgroundQuery:=False)

最近需要使用VBA來抓取一些網頁上的資料,所以使用到網頁外部資料匯入,

當開始錄製巨集,就發現出現了錯誤,重複幾次亦是如此,檢視了一下程式碼,

總是在 .Refresh BackgroundQuery:=False 這行程式碼出現錯誤,想問要如何證才正確?

'***********************
' 下載上市融資餘額資料
'***********************
Sub WebQuery_TWII_Credit(theDATE As String)
                           
    Dim theURL, saveSheetName As String
        
    saveSheetName = "download2"
   
    With Sheets(saveSheetName)
        .Visible = True
        .Select
        .Cells.Clear
    End With
   
    theURL = "http://www.tse.com.tw/ch/trading/exchange/MI_MARGN/MI_MARGN_2.php?select2=MS&type=list&input_date=" & theDATE
   
    With Sheets(saveSheetName).QueryTables.Add(Connection:="URL;" & theURL, Destination:=Range("A1"))
        .Name = "Credit"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .Refresh BackgroundQuery:=False
        .Delete  '記得手動加入
    End With
        
End Sub

謝謝大家的回覆,你們提供的方法我都試試看,感恩~

TOP

        靜思自在 : 盡多少本份,就得多少本事。
返回列表 上一主題