- ©«¤l
- 5923
- ¥DÃD
- 13
- ºëµØ
- 1
- ¿n¤À
- 5986
- ÂI¦W
- 0
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- Office 2010
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW°ò¶©
- µù¥U®É¶¡
- 2010-5-1
- ³Ì«áµn¿ý
- 2022-1-23
|
¥»©«³Ì«á¥Ñ GBKEE ©ó 2022-1-11 15:54 ½s¿è
¦^´_ 11# wufonna
Pchome ªº½u«¬¨«¶Õ ºô¶ VBA °Ñ¦Ò ¬Ý¬Ý- Option Explicit
- Dim Rng As Range, ¸ê°T_Msg As Boolean, ie As New InternetExplorer
- Sub AllFile() '«·s§ó·s©Ò¦³¸ê®Æ
- Dim i As Integer
- With Sheets("ªÑ²¼")
- .UsedRange.CurrentRegion.Offset(0, 1).Clear
- ¸ê°T_Msg = True
- For i = 1 To .Range("A" & .Rows.Count).End(xlUp).Row
- µ{¦¡°õ¦æ Cells(i, 1)
- Next
- ¸ê°T_Msg = False
- If ¸ê°T_Msg = False Then ie.Quit
- End With
- End Sub
- Sub ex()
- µ{¦¡°õ¦æ [B1]
- End Sub
- Private Sub µ{¦¡°õ¦æ(xRng As Range) '³æµ§§ó·s «ü©wAÄ檺¸ê®Æ
- If xRng.Column > 1 Then MsgBox xRng & " ¤£¦b AÄæ": Exit Sub
- ' If ie Is Nothing Then Set ie = New InternetExplorer
- Set Rng = xRng
- ªÑ²¼¸ê°T
- Rng.Select
- If ¸ê°T_Msg = False Then ie.Quit
- End Sub
- Sub ªÑ²¼¸ê°T()
- Dim E As Object, Ar(), A As Integer, R As Integer, C As Integer
- With Rng
- A = .Parent.UsedRange.Columns.Count - 1
- If ¸ê°T_Msg = False Then
- .Offset(, 1).Resize(, A).Select
- .Offset(, 1).Resize(, A).Clear
- End If
- If .Row = 1 Then .Cells(1, 2) = "ªÑ²¼¦WºÙ ": .Cells(1, 3) = "ªÑ²¼»ù®æ "
- End With
- On Error GoTo Beerr
- Be:
- With ie
- DoEvents
- .Navigate "https://pchome.megatime.com.tw/stock/sid" & Rng & ".html" '
- ' .Visible = True
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- Do: DoEvents
- If InStr(.Document.body.innertext, "¬dµL") Then '¬dµL ªÑ²¼¥N¸¹
- Rng.Offset(, 1) = "¬dµL " & Rng: Exit Sub
- ie.Quit
- End If
- Loop Until Not InStr(.Document.body.innertext, "¬dµL")
- If Rng.Row > 1 Then
- Do: DoEvents
- Set E = .Document.querySelector("em[class='corp-name']") '«ü©w³o¤¸¯À <em> Ū¨ú (ªÑ²¼¦WºÙ, ¥N¸¹)
- '<em class="corp-name">¥x¡@ªd<span class="stock-code"> (1101)</span> </em>
- Loop Until TypeName(E) = "HTMLPhraseElement"
- If Trim(E.ALL.TAGS("SPAN")(0).innertext) <> "(" & Rng & ")" Then
- Rng.Offset(, 1) = "¬dµL " & Rng: Exit Sub
- Else
- Rng.Cells(, 2) = Trim(Split(E.innertext, "(")(0)) 'Split ¨ç¼Æ ¶Ç¦^¤@Ó³¯¦C¯Á¤Þ±q¹s¶}©lªº¤@ºû°}¦C , ¥¦¥]§t«ü©w¼Æ¥Øªº¤l¦r¦ê
- End If
- Set E = .Document.getelementbyid("stock_info_data_a").ALL.TAGS("SPAN")(0) 'ªÑ²¼»ù®æ id="stock_info_data_a"
- '<div class="price s-down fadein_black" id="stock_info_data_a">
- '<span class="data_close s-down">18.95</span> **TAGS("SPAN")(0) 's-down ªÑ»ù¤U°
- '<span class="data_diff s-down">¡¿-0.10</span> **TAGS("SPAN")(1)
- '<span class="data_diff s-down">-0.52%</span> **TAGS("SPAN")(2)
- '<span class="data_total">18.79<em>»õ</em></span></div> **TAGS("SPAN")(3)
- Rng.Cells(, 3) = E.innertext
- End If
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- Do: DoEvents
- Set E = .Document.ALL.TAGS("table")(1)
- Loop Until TypeName(E) = "HTMLTable"
- If Rng.Row > 1 Then Ar = Array(3, 5, 7, 9) Else Ar = Array(2, 4, 6, 8)
- 'Rng.Row > 1 >>±q²Ä2¦C¶}©l¤U¸ü¸ê®Æ
- 'Array(2, 4, 6, 8) ¬°¼ÐÃDªºRow **Ar = Array(3, 5, 7, 9 )¬°¸ê®ÆªºRow
- A = 4 '³]©w¸ê®ÆÄæ¦ìªº°_©lÄæ¦ì,«e¦³ 1ªÑ²¼¥N½XÄæ,2ªÑ²¼¦WºÙÄæ,3ªÑ²¼»ù®æÄæ
- For R = 0 To UBound(Ar) - 1
- For C = 0 To E.Rows(Ar(R)).Cells.Length - 1
- Rng.Cells(, A) = E.Rows(Ar(R)).Cells(C).innertext
- A = A + 1 '¸ê®ÆÄæ¦ì+1
- Next
- Next
- End With
- Exit Sub
- Beerr:
- Set ie = New InternetExplorer
- GoTo Be
- End Sub
½Æ»s¥N½X |
|