- ©«¤l
- 23
- ¥DÃD
- 0
- ºëµØ
- 0
- ¿n¤À
- 73
- ÂI¦W
- 280
- §@·~¨t²Î
- XP
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2012-4-21
- ³Ì«áµn¿ý
- 2024-11-6
|
¦^´_ azrael19
¦³¤@Ó©µ¦ùªº°ÝÃD ¯à§_§PŪ¦pªþ¹Ï¤º¥kºÝ¾ã±Æ¸ê®Æ¤§º¦©Î¶^
©Î¥i±N¹ê»Ú¤§½bÀY¤è¦V¤@ ...
lcctno µoªí©ó 2015-7-26 11:13
¥Î쥻ªº¤è¦¡§ÚÁÙ¤£ª¾¹Dn«ç»ò°µ¡A¦pªG§Aªº»Ý¨D¥u¬On§ì¸ê®Æ¡A¤U±¬O¥t¤@ºØ¤è¦¡§A¸Õ¸Õ¬Ý...- Option Explicit
- Option Base 1
- Sub Ex()
- Dim HEAD As Variant, PARAM As Variant, PA As Variant, AR As Variant, v As Variant
- Dim i As Integer, j As Integer, k As Integer
- Dim s As String, ErrDescription As String
- Dim objCol As Object
-
- '°Ñ¼Æ : ºô§},ªíÀY©ñ¸m¦ì§},¸ê®Æ©ñ¸mÀx¦s®æ¦ì§},¼ÐµùÃC¦âÀx¦s®æ¦ì§}
- PARAM = [{"http://www.yuantaetfs.com/api/RtNav","B1","B5","D16:D17"; "http://www.yuantaetfs.com/Home/IndexPrice","","B27","C27:C28"}]
-
- '¸ê®ÆªíÀY°}¦C¦r¦ê
- HEAD = Array("{""¸ê®Æ®É¶¡"","""","""","""","""","""","""","""","""","""","""","""","""","""","""";" & _
- """°ò¥»¸ê®Æ"","""",""²bÈ"","""","""","""",""¥«»ù"","""","""","""",""§é·¸»ù"","""",""ªì¯Å¥«³õ"","""",""°òª÷"";" & _
- """ªÑ²¼"",""°òª÷"",""¬Q¦¬"",""¹w¦ô"",""º¦¶^"",""º¦¶^´T"",""¬Q¦¬"",""³Ì·s"",""º¦¶^"",""º¦¶^´T"",""§é·¸»ù"",""´T«×"",""¥i§_"",""¥i§_"",""Àç·~¤é"";" & _
- """¥N½X"",""¦WºÙ"",""²bÈ"",""²bÈ"","""","""",""¥«»ù"",""¥«»ù"","""","""","""","""",""¥ÓÁÊ"",""Å«¦^"",""""}", "")
-
- 'Regular Expression
- PA = Array("{""fundId"":""[\d]+"",""etfId"":""(.+?)"",""name"":""(.+?)"",""ename"":""[^""]*"",""yestNav"":(.+?),""nav"":(.+?),""navFluct"":(.+?),""yestPrice"":(.+?),""price"":(.+?),""priceFluct"":(.+?),""yestIndex"":(.+?),""index"":(.+?),""indexFluct"":(.+?),""updateTime"":""(.+?)"",""AllowMark"":""(.+?)"",""RedemMark"":""(.+?)"",""BussMark"":""(.+?)"",[^}]+}", _
- "{""fund_id"":null,""IndexCode"":""[^""]*"",""IndexName"":""([^""]+)"",""IndexEName"":""[^""]*"",""crncy"":""[^""]*"",""area"":""D"",""DayDate"":""[^""]*"",""Close"":(.+?),""yestClose"":(.+?),""Diff"":(.+?)}")
- ActiveSheet.UsedRange.ClearContents
-
- For i = LBound(PARAM) To UBound(PARAM)
-
- '§ì¨úJSON¸ê®Æ
- With CreateObject("WinHttp.WinHttpRequest.5.1")
- .Open "GET", PARAM(i, 1), False
- .send
- If 200# <> .Status Then
- ErrDescription = "ºô¶Åª¨ú¥¢±Ñ!"
- GoTo Catch
- End If
- s = .responseText
- End With
-
- With ActiveSheet
- If "" <> PARAM(i, 2) Then
- '©ñ¸mªíÀY¸ê®Æ
- AR = Application.Evaluate(HEAD(i))
- .Range(PARAM(i, 2)).Resize(UBound(AR, 1), UBound(AR, 2)).Value = AR
- Erase AR
- End If
- If "" <> PA(i) Then
- '¸ÑªRJSON¦r¦ê¤¤©Ò»Ý¸ê®Æ
- With CreateObject("VBScript.RegExp")
- .Global = True
- .Pattern = PA(i)
- If False = .test(s) Then: GoTo Catch
- Set objCol = Nothing
- Set objCol = .Execute(s)
- End With
- If 0 = objCol.Count Then
- ErrDescription = "¸ê®Æ®æ¦¡¸ÑªR¿ù»~!"
- GoTo Catch
- End If
- ReDim AR(1 To objCol.Count, 1 To objCol(1).SubMatches.Count) As Variant
- For j = 0 To objCol.Count - 1
- For k = 0 To objCol(0).SubMatches.Count - 1
- AR(j + 1, k + 1) = objCol(j).SubMatches(k)
- Next k
- Next
- End If
-
- Select Case i
- Case 1
- '«·s±Æ¦C¤Î×¥¿¸ê®Æ¥H²Å¦Xºô¶ªí®æ©Ò§e²{¼Ë»ª
- For j = 0 To objCol.Count - 1
- AR(j + 1, 9) = AR(j + 1, 8) 'º¦¶^
- AR(j + 1, 8) = AR(j + 1, 7) '³Ì·s¥«»ù
- AR(j + 1, 7) = AR(j + 1, 6) '¬Q¦¬¥«»ù
- AR(j + 1, 6) = Round(AR(j + 1, 5) / AR(j + 1, 3), 4) 'º¦¶^´T
- AR(j + 1, 10) = Round(AR(j + 1, 9) / AR(j + 1, 7), 4) 'º¦¶^´T
- AR(j + 1, 11) = AR(j + 1, 8) - AR(j + 1, 4) '§é·¸»ù
- AR(j + 1, 12) = Round(AR(j + 1, 11) / AR(j + 1, 4), 4) '´T«×
- Next j
- .Range("B1").Value = "¸ê®Æ®É¶¡:" & Trim(objCol(0).SubMatches(11))
- With .Range(PARAM(i, 3)).Resize(UBound(AR, 1), UBound(AR, 2))
- '³]©wÀx¦s®æ®æ¦¡
- v = Split("@,@,0.00,0.00,0.00,0.00%,0.00,0.00,0.00,0.00%,0.00,0.00%", ",")
- For j = LBound(v) To UBound(v)
- .Columns(j + 1).NumberFormat = v(j)
- Next
- .Value = AR
- End With
- Erase AR
- Case 2
- For j = 0 To objCol.Count - 1
- AR(j + 1, 3) = AR(j + 1, 4) '«ü¼Æº¦¶^
- AR(j + 1, 4) = Round(AR(j + 1, 3) / AR(j + 1, 2), 4) 'º¦¶^´T(%)
- Next
- With .Range(PARAM(i, 3)).Resize(UBound(AR, 1), UBound(AR, 2))
- '³]©wÀx¦s®æ®æ¦¡
- v = Split("@;#,##0.00;#,##0.00;0.00%", ";")
- For j = LBound(v) To UBound(v)
- .Columns(j + 1).NumberFormat = v(j)
- Next
- .Value = AR
- End With
- Erase AR
- Case Else
- End Select
-
- '¼Ðµù³]©wÀx¦s®æ¦ì§}ÃC¦â
- With .Range(PARAM(i, 4)).Interior
- .ColorIndex = 35
- .Pattern = xlSolid
- End With
- End With
-
- Next
-
- Finally:
- Set objCol = Nothing
- Exit Sub
- Catch:
- If "" <> ErrDescription Then: MsgBox ErrDescription, vbCritical
- Err.Clear
- Resume Finally
- End Sub
½Æ»s¥N½X |
|