·Q½Ð±Ð³o¬O³o¬O²{ª÷¬y¶qªíªººô¶
http://mops.twse.com.tw/mops/web/t164sb05
³z¹L¤Wzµ{§Ç§ì¨ú«á¦bexcelªí¤W¦r¦êµLªk§e²{ªí®æ,½Ð°Ýn¦p¦óקï
A = Split(.Document.getelementsbytagname("table")(16).innertext, vbLf)'³o¦æ§Ú16§ï3
A = Split(.Document.getelementsbytagname("table")(3).innertext, vbLf)
Option Explicit
Sub Ó§O²{ª÷¬y¶qªí()
Dim i, r As Integer, A As Variant, AA As Variant
With CreateObject("InternetExplorer.Application")
.Navigate "http://mops.twse.com.tw/mops/web/t164sb05"
.Visible = True
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
With .Document
.getelementsbytagname("input")(38).Value = "5349" '³o¸Ì×§ï ªÑ²¼¥N¸¹
.getelementsbytagname("input")(41).Click
End With
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
'******************************
r = 1
Cells.Clear
A = Split(.Document.getelementsbytagname("table")(3).innertext, vbLf)
For i = 0 To UBound(A)
AA = Trim(A(i))
Do While InStr(AA, Space(5))
AA = Replace(AA, Space(5), Space(4))
Loop
AA = Split(AA, Space(2))
Cells(r, 1).Resize(, UBound(AA) + 1) = AA
r = r + 1
Next
.Quit
End With
'******************************
¸ê®Æ¾ã²z
End Sub
Private Sub ¸ê®Æ¾ã²z()
Dim A, i
Application.DisplayAlerts = False
With ActiveSheet
.Range("B:B,D").Delete Shift:=xlToLeft
With .Range("B:C")
.Replace Chr(32) & Chr(13), "", xlPart '²M°£¤£¥i¨£¦r¤¸
.Replace Chr(41) & Chr(13), ")" '²M°£¤£¥i¨£¦r¤¸
.Replace "$", ""
.Replace ",", ""
.NumberFormatLocal = "#,##0_);[¬õ¦â](#,##0)"
.HorizontalAlignment = xlRight
.VerticalAlignment = xlCenter
End With
With .Range("A2:C2,A3:C3,A4:C4,A5:C5")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Merge
.Areas(4).HorizontalAlignment = xlRight
End With
.[A6:A7].Insert Shift:=xlToRight
i = 8
Do While .Cells(i, 1) <> ""
If InStr(.Cells(i, 1), String(2, Mid(.Cells(i, 1), 1, 1))) Then
.Cells(i, 1).Resize(, 3).Merge
.Cells(i, 1).Resize(, 3).HorizontalAlignment = xlCenter
ElseIf Len(.Cells(i, 1)) >= 15 Then
.Cells(i, 1).WrapText = True
End If
i = i + 1
Loop
Range("A:A").ColumnWidth = 40
.Range("B:C").EntireColumn.AutoFit
End With
Application.DisplayAlerts = True
End Sub