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作者: paul3063 時間: 2018-1-6 20:59
題外話,
其實中間有試著將巨集改成
Sub test()
X = InputBox()
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.twse.com.tw/exchangeReport/MI_INDEX?response=html&date=" & X & "&type=ALLBUT0999" _
, Destination:=Range("A1"))