- 帖子
- 7
- 主題
- 3
- 精華
- 0
- 積分
- 60
- 點名
- 0
- 作業系統
- xp
- 軟體版本
- Office 2003
- 閱讀權限
- 20
- 性別
- 女
- 來自
- 台中
- 註冊時間
- 2012-3-20
- 最後登錄
- 2023-1-12
   
|
[發問] 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 |
|