¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-6-15 15:21 ½s¿è
½Ð°Ý¦U¦ì¤j¤j¡A
¥Ñºô¶¨ú±oªº¸ê®Æ¡A¤£ª¾¹Dn¦p¦ó¦P¨B½s½X¦¨¥¿½T¤§¤¤¤å½X¦^¶Ç¡A
¦pªþ¹Ï (¤W¹Ï) ¡G
¥¿½TÀ³¬° (¤U¹Ï) ¡G
- Sub ¤W¥«·í¨R4()
- Dim xTable As Object, k As Integer, c As Integer, R As Integer ' , sn As Integer
- Dim url As String, cts As Integer, E As Variant, xDate As String ' , rc As Integer
- Dim oXmlhttp As Object, oHtmldoc As Object, select2 As String ' , tm
- Dim TVal() As Variant, sPost As String
-
- If Select_Name = -1 Then Exit Sub
- TVal = Array("MS", "", "0049", "0099P", "019919T", "0999", "0999P", "01", "02", "03", _
- "04", "05", "06", "07", "21", "22", "08", "09", "10", _
- "11", "12", "13", "24", "25", "26", "27", "28", "29", _
- "30", "31", "14", "15", "16", "17", "18", "23", "9299", "19", "20", "CB")
-
- url = "http://www.twse.com.tw/ch/trading/exchange/TWTB4U/TWTB4U.php"
- xDate = Format(Sheets("Á`ªí").[B1], "EE/MM/DD")
- sPost = "input_date=" & Replace(xDate, "/", "%2F") & "&select2=" & TVal(Select_Name) 'urlencode
-
- Set oXmlhttp = CreateObject("msxml2.xmlhttp")
- Set oHtmldoc = CreateObject("htmlfile")
-
- With Sheets("¤W¥«")
- .Select
- .Cells.Clear
-
- With oXmlhttp
- .Open "Post", url, False
- ' .setRequestHeader "Connection", "Keep-Alive" ' µu®É¶¡¤º¦h¦¸¬d¸ß«Øij¥i¥[³o¦æ
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .setRequestHeader "Content-Length", Len(sPost)
- .Send sPost
- ' ¤W± Open °Ñ¼Æ¥Î False (=¦P¨B)¡A¥i¥H¤£¥Î¦A§PÂ_ status
- ' Do While .Status <> 200 Or .readyState <> 4: DoEvents: Loop
- oHtmldoc.write .responseText
- ' MsgBox .responseText
- End With
-
- Set xTable = oHtmldoc.all.tags("TABLE")
- ' Stop
- For Each E In Array(8, 10) ' 8, 10 -> "TABLE"
- Set xTable = oHtmldoc.all.tags("TABLE")(E)
- ' Set xTable = oHtmldoc.all.tags("TABLE")(0)
- k = k + 1
-
- For R = 0 To xTable.Rows.Length - 1
- For c = 0 To xTable.Rows(R).Cells.Length - 1
- Sheets("¤W¥«").Cells(k, c + 1) = xTable.Rows(R).Cells(c).INNERTEXT
- Next
- k = k + 1
- Next
- If Right(sPost, 3) <> "t2=" Then Exit For
- Next
- End With
- End Sub
½Æ»s¥N½X- Private Function Select_Name() As Integer
- With Sheets("Á`ªí").ComboBox1
- If .ListIndex = -1 Then MsgBox ("±z©|¥¼¿ï¾Ü¡u²£·~Ãþ§O¡v¡A½Ð©ó" & vbCrLf & "½T»{«á¦A¦¸ÂI¿ï¡y¶}±Òºô¶¡z¡A" & vbCrLf & "ÁÂÁ±z¡I")
- Select_Name = .ListIndex ' Select_Name = -1,0,1,2,3,4,5,6,7,8,9,.....39
- End With
- End Function
½Æ»s¥N½X ÁÂÁ¦U¦ì¤j¤j¡I |