Dim i As Integer, s As Integer, k As Integer, A, ii, j
Dim STK_NO As String '股票代碼 INPUT
Dim myear As String '年度 SELECT
Dim mmon As String '月份 SELECT
STK_NO = "2330"
myear = "102"
mmon = "5"
With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/STOCK_DAYMAIN.php"
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
With .document
For Each A In .getelementsbytagname("INPUT")
If A.Name = "STK_NO" Then A.Value = STK_NO
Next
For Each A In .getelementsbytagname("SELECT") '己經指定年份,但實際並取得指定年份
If A.Name = "myear" Then
A.Value = True
A.Focus
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "{DOWN}"
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "{ENTER}"
Exit For
End If
Next
For Each A In .getelementsbytagname("SELECT") '己經指定月份,但實際並取得指定月份
If A.Name = "mmon" Then
A.Value = True
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "{DOWN}"
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "{ENTER}"
Exit For
End If
Next
For Each A In .getelementsbytagname("INPUT")
If Trim(A.Value) = "查詢" And A.Name = "login_btn" Then A.Click '
Next
End With
Application.Wait Now + #12:00:10 AM#
Set A = .document.getelementsbytagname("table")
On Error Resume Next
With ActiveSheet
.Cells.Clear
For ii = 1 To A.Length - 1
For i = 0 To A(ii).Rows.Length - 1 '寫入資料
k = k + 1
For j = 0 To 8
Cells(k, j + 1) = A(ii).Rows(i).Cells(j).innerText
Next
Next
Next