- ©«¤l
- 96
- ¥DÃD
- 18
- ºëµØ
- 0
- ¿n¤À
- 125
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Office 2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2014-3-23
- ³Ì«áµn¿ý
- 2022-8-2
|
¦^´_ 85# GBKEE
¤£¦n·N«ä¡A§Ú°õ¦æ«á¦ü¥G·|¥d¦b¹Ï¤¤ªº°j°é¡A¤£ª¾¯à§_½Ð±z°õ¦æ¬Ý¬Ý¬O§_¦³¤@¼Ë±¡§Î©O¡H
- Option Explicit
- Dim IE As Object
- Sub IE_Application()
- Set IE = CreateObject("InternetExplorer.Application")
- With IE
- .Navigate "http://www.twse.com.tw/ch/trading/exchange/FMSRFK/FMSRFKMAIN.php"
- ' .Visible = True '¤£Åã¥Üie
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- End With
- End Sub
- Sub ¤W¥«¤ë¦¨¥æ¸ê°T()
- Dim Rng As Range, Rng1 As Range, E As Range, X As Range, T As Date, xPath As String, xFile As String
- Dim Ea As Variant, ar(), ii, aa As Integer
- T = Time
- Application.DisplayStatusBar = True
- '½Ð±N¤W¥«ªºªÑ²¼¥N¸¹,¦b Sheets(3).Range("A1")©¹¤UKey¤W,°j°é¨Ì³o¸ÌªºªÑ²¼¥N¸¹¶×¤J
- Set Rng = ThisWorkbook.Sheets(3).Range("A:A")
- Set Rng1 = ThisWorkbook.Sheets(3).Range("b:b")
- If Application.Count(Rng) = 0 Then MsgBox "¨S¦³ªÑ²¼¥N¸¹": Exit Sub
- If Application.Count(Rng1) = 0 Then MsgBox "¨S¦³ªÑ²¼¥N¸¹": Exit Sub
- Set Rng = Rng.SpecialCells(xlCellTypeConstants)
- Set Rng1 = Rng1.SpecialCells(xlCellTypeConstants)
- xPath = "F:\°]³ø¸ê®Æ"
- IE_Application '
- Application.StatusBar = " "
- For Each E In Rng
- MR:
- With Sheets(1)
- .Activate
- .Cells.Clear '¤U¸ü¸ê®Æ¸m©ó¦¹¤u§@ªí,ÅÜ´«ªÑ²¼®É:²MªÅ
- End With
- For Each X In Rng1
- With IE
- .Document.getElementsByTagName("select")("Yy").Value = X
- 'yy -> ¦~«×,mm -> ¤ë¥÷, dd -> ¤é´Á
- .Document.getelementsbyname("stockNo")(0).Value = E
- 'ªÑ²¼¥N½X stockNo '**¤j¤p¼gn¤@P**
- ' .Document.getelementsbyname("query-button")(0).Click '«ö¤U¬d¸ß
- For Each Ea In .Document.body.all.tags("a")
- If Ea.classname = "button search" Then
- Ea.Click: Exit For '«ö¤U¬d¸ß
- End If
- Next
- Do While .Busy Or .readyState <> 4: Loop
- On Error Resume Next
- If InStr(.Document.getElementsByTagName("TABLE")(3).outerHTML, "¬dµL") Then GoTo Nn
- If .Document.getElementsByTagName("TABLE")(3).Rows.Length > 1 Then
- Ep .Document.getElementsByTagName("TABLE")(3).outerHTML
- Else
- GoTo Nn
- End If
- ' If InStr(Selection.Cells(3, 1), "¬dµL") Then Selection.Delete Shift:=xlUp: GoTo Nn
- End With
- With Sheets(1)
- aa = Selection.Range("a3")
- ' If aa = "" Then aa = Selection.Range("a1") '·|¥X¿ù¤~¥[¤J³o¬q
- If aa + 1911 <> X Then GoTo MR
- End With
- Next X
- Nn:
- If Sheets(1).Range("a1") = "" Then GoTo KK
- xFile = xPath & "\" & E & "\HPM.txt"
- MkDir_Sub xFile
- Maketxt xFile, Sheets(1).Range("A1").CurrentRegion, E.Value
- ii = ii + 1
- Application.StatusBar = Application.Text(Time - T, ["MM¤ÀSS¬í"]) & " ¶×¤J¤W¥«¤ë¦¨¥æ " & E & "¦@" & ii & " ¤å¦rÀÉ"
- KK:
- Next E
- IE.Quit
- Application.StatusBar = Application.Text(Time - T, ["MM¤ÀSS¬í"]) & " ¦@¶×¤J¤W¥«¤ë¦¨¥æ " & ii & " ¤å¦rÀÉ, Ū¨ú§¹²¦ !! "
- MsgBox "¶×¤J ¤å¦rÀÉ" & ii & " ¶O®É " & Application.Text(Time - T, ["MM¤ÀSS¬í"])
- ' ThisWorkbook.Save
- End Sub
- Sub Ep(S As String)
- Dim D As New DataObject, i As Integer, FormDLL As String, Rng As Range
- 'DataObject ª«¥ó ¦b¶i¦æÂà´«°Ê§@®É¡A°µ¬°®æ¦¡¤Æ¤å¦r¸ê®Æªº¼È¦s°Ï°ì¡C¨ä¤]¥i¥H¼È¦s©MÀx¦s¦b DataObject ªº¤å¦r¤ù¬q¬ÛÃöªº®æ¦¡¡C
- '«Å§i Dim D As New DataObject '¶·¦b¤u¨ã-> ³]©w¤Þ¥Î¶µ¥Ø¥[¤J ·s¼W¤Þ¥Î Microsoft Forms 2.0 Object Library ,±M®× ¥[¤J¤@ªí³æ§Y¥i
- On Error GoTo ER
- With D
- .SetText S
- .PutInClipboard
- With Sheets(1)
- With .Range("a" & .Rows.Count).End(xlUp)
- If .Row = 1 Then
- Set Rng = .Cells
- Else
- Set Rng = .Offset(1)
- End If
- Rng.Select
- .Parent.PasteSpecial Format:="Unicode ¤å¦r"
- Set Rng = Rng.Range("A3", Rng.Range("A3").End(xlDown)).Resize(, 9)
- With Sheets(1).Sort
- .SetRange Rng
- .Header = xlGuess
- .MatchCase = False
- .Orientation = xlTopToBottom
- .SortMethod = xlPinYin
- .Apply
- End With
- 'Sort :¸ê®Æ±Æ§Ç
- ' Rng.Sort Key1:=Rng.Range("B2"), Order1:=xlDescending, Header:=xlYes ', _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
- :=xlStroke, DataOption1:=xlSortNorma
- ' If .Row = 1 Then
- ' .Range("A2").EntireRow.Delete
- ' Else
- ' .Range("A2:A4").EntireRow.Delete
- ' End If
- End With
- End With
- End With
- Exit Sub
- ER:
- ThisWorkbook.VBProject.References.AddFromFile "C:\windows\system32\FM20.DLL"
- Resume
- End Sub
- Sub Maketxt(xF As String, Q As Range, Code As String) '±N¶×¤J¸ê®Æ¦s¤J«ü©wªºtxt
- Dim fs As Object, E As Range, C As Variant, A As String, B As Integer, D As String
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set fs = fs.CreateTextFile(xF, True) '³Ð¨£¤@ÓÀÉ®×,¦pÀɮצs¦b¥iÂл\±¼
- A = Q.Cells(1)
- B = Len(A)
- If B >= 25 Then
- D = Mid(A, 11, 4)
- Else
- D = Mid(A, 11, 2)
- End If
- Q.Cells(1) = Code & "-" & D & "" & " ¤ë¦¨¥æ¸ê®Æ" '¥[¤JªÑ²¼¥N¸¹
- If Q.Cells(3, 1).Offset(1) = "" Then GoTo EE
- Q.Range("a3", Q.Range("a3").End(xlDown)).Replace "¦~«×", ""
- Q.Columns(1).SpecialCells(xlCellTypeBlanks).Offset(-1).EntireRow.Delete
- Q.Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
- EE:
- For Each E In Q.Rows
- C = Application.Transpose(Application.Transpose(E.Value))
- C = Join(C, vbTab)
- fs.Write C
- Next
- fs.Close
- End Sub
- Sub MkDir_Sub(S As String)
- Dim ar, i As Integer, xPath As String
- If Dir(S) = "" Then
- ar = Split(S, "\")
- xPath = ar(0)
- For i = 1 To UBound(ar) - 1
- xPath = xPath & "\" & ar(i)
- If Dir(xPath, vbDirectory) = "" Then MkDir xPath
- Next
- End If
- End Sub
½Æ»s¥N½X
¤W¥«¤ë¦¨¥æ¸ê°T.zip (39.22 KB)
|
|