返回列表 上一主題 發帖

[發問] (EXCEL VBA問題)請問怎樣用QueryTable抓取網頁資料?

修改抓取表格參數你試看看

Sub Ex()
        Dim xDay As String
        xDay = InputBox("輸入日期", "大盤統計資訊日期", Date)
        If IsDate(xDay) Then
            If Weekday(xDay, vbMonday) < 6 Then
                xDay = Format(xDay, "yyyymmdd")
                With ActiveSheet.QueryTables.Add(Connection:= _
                    "URL;http://www.twse.com.tw/exchangeReport/MI_INDEX?response=html&date=" & xDay & "&type=ALLBUT0999" _
                    , Destination:=Range("A1"))
                    .WebFormatting = xlNone
                    .RefreshStyle = xlInsertDeleteCells
                    .AdjustColumnWidth = True
                    .Refresh BackgroundQuery:=True
                End With
            Else
                MsgBox xDay & "  假日沒營業"
            End If
        Else
            MsgBox "日期輸入錯誤"
        End If
    End Sub
Rogersg

TOP

        靜思自在 : 一個人的快樂.不是因為他擁有得多,而是因為他計較得少。
返回列表 上一主題