返回列表 上一主題 發帖

[發問] 網站透過QueryTable下載的日期問題

回復 1# PKKO

試試看這個:
    Sub test1()
Dim QT As QueryTable
Dim WebAddress As String
    ' WebAddress = "http://www.cnyes.com/twstock/ps_historyprice/2327.htm"

WebAddress = "https://www.cnyes.com/twstock/ps_historyprice.aspx?"
WebAddress = WebAddress & "code=2327"
WebAddress = WebAddress & "&ctl00$ContentPlaceHolder1$startText=2019/01/01"
WebAddress = WebAddress & "&ctl00$ContentPlaceHolder1$endText=2020/03/06"

With ThisWorkbook.Worksheets("DL")
    .Cells.Clear
    Set QT = .QueryTables.Add("URL;" & WebAddress, .Range("$A$1"))
End With
With QT
   ' .PostText = "ctl00$ContentPlaceHolder1$startText=" & " 2019/01/01" & "&ctl00$ContentPlaceHolder1$endText=" & " 2020/03/06"
.WebTables = "1"
.Refresh False
.Delete
End With
End Sub

TOP

本帖最後由 Scott090 於 2020-3-8 14:34 編輯

回復 3# PKKO

再測試如下:
       Sub test1()
Dim QT As QueryTable
Dim WebAddress As String
  '  WebAddress = "http://www.cnyes.com/twstock/ps_historyprice/2327.htm"

WebAddress = "https://www.cnyes.com/twstock/ps_historyprice.aspx?code=2327"
With ThisWorkbook.Worksheets("DL")
    .Cells.Clear
    Set QT = .QueryTables.Add("URL;" & WebAddress, .Range("$A$1"))
End With
With QT
     '.PostText = "ctl00$ContentPlaceHolder1$startText=" & " 2019/01/01" & "&ctl00$ContentPlaceHolder1$endText=" & " 2020/03/06"
'日期與等號間不要有空格
'======================
   .PostText = "ctl00$ContentPlaceHolder1$startText=" & "2019/01/01" & "&ctl00$ContentPlaceHolder1$endText=" & "2020/03/06"
.WebTables = "1"
.Refresh False
.Delete
End With
End Sub

TOP

        靜思自在 : 信心、毅力、勇氣三者具備,則天下沒有做不成的事。
返回列表 上一主題