Sub 匯入今日股市資料()
Set ie = CreateObject("internetexplorer.application")
For Each stock In Range("a1:a28")
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = stock
ie.navigate "https://tw.stock.yahoo.com/s/list.php?c=" & stock
Do While ie.readystate <> 4 Or ie.busy
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:05"))
Set tbl = ie.Document.getElementsByTagName("table")(4)
Set trs = tbl.getElementsByTagName("tr")
For i = 0 To trs.Length - 1
Set tds = trs(i).getElementsByTagName("td")
If tds.Length = 0 Then Set tds = trs(i).getElementsByTagName("th")
For j = 0 To tds.Length - 1
Cells(i + 1, j + 1) = tds(j).innertext
Next
Next
Columns(1).Delete
Columns.AutoFit
Next
End Sub
