- ©«¤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
|
¦^´_ 62# GBKEE
ª©¥D±z¦n¡A¤£¦n·N«ä¡A§Ú¦³¸ÕµÛ±NFor x = A - 1 To A §ï¦¨For x = 0 To A¡A¤£¹L¥X¿ù°T®§©M¥X¿ù¦ì¸m¤´¬Û¦P¡A¯à¤£¯à¦A³Â·Ð±z´ú¸Õ¤@¤U©O¡H
¥t¥~¦b§ó¤§«eªº¤WÂd¦~¦¨¥æ¸ê®Æ¡A´N¬O¥Î¤ñ¸ûªº¼gªk¡A¤£¶K¤WEXCELª½±µ¼g¤JTXTªºµ{¦¡½X¡AÁöµM¦³¸ê®Æ¡A¤£¹L³Ì¤W¤è¤Ö¤FӪѥN¸¹©M¦WºÙ¡A¤£ª¾³o³¡¤À¯à¤£¯à
¤]Â^¨ú¨ì¸ê®Æ¨Ã¼g¤JTXT¡H©Î¬O¬O¦³¥i¥H¥ý¶K¨ìEXCEL¦A¼g¤JTXTªº¤èªk¡H¦A³Â·Ð±z¤F¡I- Option Explicit
- Dim IE As Object, A As Integer
- Sub IE_Application()
- Dim I As Integer
- Set IE = CreateObject("InternetExplorer.Application")
- With IE
- .Navigate "http://www.tdcc.com.tw/smWeb/QryStock.jsp"
- .Visible = True '¤£Åã¥Üie
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- 'Ū¨ú¶°«O¤áªÑÅv¤À´²ªí¬d¸ßªº¸ê®Æ¤é´ÁÁ`Ó¼Æ
- A = .document.getelementsByTagName("select")("SCA_DATE").Length - 1
- End With
- End Sub
- Sub ¶°«O()
- Dim Rng As Range, E As Range, x As Variant, T As Date, xPath As String, xFile As String
- Dim Ea As Variant, ii As Integer
- T = Time
- Application.DisplayStatusBar = True
- '½Ð±N¤WÂdªºªÑ²¼¥N¸¹,¦b Sheets(3).Range("A1")©¹¤UKey¤W,°j°é¨Ì³o¸ÌªºªÑ²¼¥N¸¹¶×¤J
- Set Rng = ThisWorkbook.Sheets(3).Range("A:A")
- If Application.Count(Rng) = 0 Then MsgBox "¨S¦³ªÑ²¼¥N¸¹": Exit Sub
- Set Rng = Rng.SpecialCells(xlCellTypeConstants)
- xPath = "D:\°]³ø¸ê®Æ"
- IE_Application '
- Application.StatusBar = " "
- For Each E In Rng
- With Sheets(1)
- .Activate
- .Cells.Clear '¤U¸ü¸ê®Æ¸m©ó¦¹¤u§@ªí,ÅÜ´«ªÑ²¼®É:²MªÅ
- End With
- For x = 0 To A
- With IE
- .document.getelementsByTagName("select")("SCA_DATE")(x).Selected = True
- '³o¸Ìªº¸ê®Æ¤é´Á »Ý¥Î Select ¥¦¬O¦³[¦~«×¤ë¥÷¤é´Á]ªº
- .document.getElementById("StockNo").Value = E
- .document.getelementsByTagName("INPUT")("sub").Click '«ö¤U¬d¸ß
- '³o¸Ìªº¬d¸ß¬O<INPUT TYPE="submit" VALUE="¬d¸ß" name="sub">
- 'End With
- Do While .Busy Or .readyState <> 4: Loop
- Ep .document.getelementsByTagName("TABLE")(7).outerHTML
- End With
- Next x
- xFile = xPath & "\" & E & "\SHD.txt"
- MkDir_Sub xFile
-
- Maketxt xFile, Sheets(1).Range("A1").CurrentRegion, E.Value
- '***·Q½Ð°Ý±zCode As StringªºCode¬O«ç»ò±a¥XӪѽs¸¹ªº ****
- 'xFile(²Ä¤@Ó¤Þ¼Æ), Sheets(1).Range("A1").CurrentRegion(²Ä¤GÓ¤Þ¼Æ),E.Value(²Ä¤TÓ¤Þ¼Æ)
-
- ii = ii + 1
- Application.StatusBar = Application.Text(Time - T, ["MM¤ÀSS¬í"]) & " ¦@¶×¤J¤W¥«¤ë¦¨¥æ " & ii & " ¤å¦rÀÉ"
- 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, E As Shape, 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)
- .Range("a" & .Rows.Count).End(xlUp).Offset(1).Select
- .PasteSpecial Format:="Unicode ¤å¦r"
- ' Set Rng = Selection
- ' Rng.Sort Key1:=Rng.Range("B2"), Order1:=xlDescending, Header:=xlYes ', _
- OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
- :=xlStroke, DataOption1:=xlSortNorma
- End With
- End With
- Exit Sub
- ER:
- FormDLL = "FM20.DLL"
- ThisWorkbook.VBProject.References.AddFromFile "C:\windows\system32\" & FormDLL
- Resume
- End Sub
- Sub Maketxt(xF As String, Q As Range, Code As String) '±N¶×¤J¸ê®Æ¦s¤J«ü©wªºtxt
- '***·Q½Ð°Ý±zCode As StringªºCode¬O«ç»ò±a¥XӪѽs¸¹ªº ****
- ' xF(±µ¦¬ªº¤Þ¼Æ¦WºÙ) As String(¦r¦ê«¬ºA), Q As Range(Rangeª«¥ó«¬ºA), Code As String(¦r¦ê«¬ºA)
- Dim fs As Object, E As Range, C As Variant
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set fs = fs.CreateTextFile(xF, True) '³Ð¨£¤@ÓÀÉ®×,¦pÀɮצs¦b¥iÂл\±¼
- For Each E In Q.Rows
- C = Application.Transpose(Application.Transpose(E.Value))
- C = Join(C, vbTab)
- fs.WriteLine 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- Option Explicit
- Dim IE As Object
- Sub IE_Application()
- Set IE = CreateObject("InternetExplorer.Application")
- With IE
- .Navigate "http://www.gretai.org.tw/ch/stock/statistics/monthly/st42.php"
- .Visible = True '¤£Åã¥Üie
- Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
- End With
- End Sub
- Sub ¤WÂd¦~¦¨¥æ¸ê°T()
- Dim E As Range, xPath As String, xFile As String, A As Object, fs As Object, F As Object, IE_URL As String
- Dim i As Integer, ii As Integer, t As Date, AR(), Rng As Range, r, C, S
- Set fs = CreateObject("Scripting.FileSystemObject")
- IE_URL = "http://www.gretai.org.tw/ch/stock/statistics/monthly/st42.php"
- t = Time
- Application.DisplayStatusBar = True
- '½Ð±N¤WÂdªºªÑ²¼¥N¸¹,¦b Sheets(3).Range("A1")©¹¤UKey¤W,°j°é¨Ì³o¸ÌªºªÑ²¼¥N¸¹¶×¤J
- Set Rng = ThisWorkbook.Sheets(3).Range("A:A")
- If Application.Count(Rng) = 0 Then MsgBox "¨S¦³ªÑ²¼¥N¸¹": Exit Sub
- Set Rng = Rng.SpecialCells(xlCellTypeConstants)
- xPath = "D:\°]³ø¸ê®Æ"
- IE_Application '
- Application.StatusBar = " "
- For Each E In Rng
- With IE
- Set A = .Document.getelementbyid("input_stock_code")
- A.Value = E
- A.ParentNode.submit
- Do While .Busy Or .ReadyState <> 4: Loop
- Set A = .Document.getelementsbytagname("TABLE")
- xFile = xPath & "\" & E & "\HPY.txt"
- MkDir_Sub xFile
- With fs.CreateTextFile(xFile, True)
- For i = 1 To A(2).Rows.Length - 1
- S = ""
- For C = 0 To A(2).Rows(i).Cells.Length - 1
- S = S & A(2).Rows(i).Cells(C).innertext & vbTab
- Next
- .WriteLine S
- Next
- .Close
- End With
- ii = ii + 1
- End With
- Application.StatusBar = Application.Text(Time - t, ["MM¤ÀSS¬í"]) & " ¦@¶×¤J¤WÂd¦~¦¨¥æ " & ii & " ¤å¦rÀÉ"
- Next
- IE.Quit
- Application.StatusBar = Application.Text(Time - t, ["MM¤ÀSS¬í"]) & " ¦@¶×¤J¤WÂd¦~¦¨¥æ " & ii & " ¤å¦rÀÉ, Ū¨ú§¹²¦ !! "
- MsgBox "¶×¤J ¤å¦rÀÉ" & ii & " ¶O®É " & Application.Text(Time - t, ["MM¤ÀSS¬í"])
- ' ThisWorkbook.Save
- 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
- Sub Maketxt(xF As String, Q As QueryTable) '±N¶×¤J¸ê®Æ¦s¤J«ü©wªºtxt
- Dim fs As Object, E As Range, C As Variant
- Set fs = CreateObject("Scripting.FileSystemObject")
- Set fs = fs.CreateTextFile(xF, True) '³Ð¨£¤@ÓÀÉ®×,¦pÀɮצs¦b¥iÂл\±¼
- For Each E In Q.ResultRange.Rows
- C = Application.Transpose(Application.Transpose(E.Value))
- C = Join(C, vbTab)
- fs.WriteLine C
- Next
- fs.Close
- End Sub
½Æ»s¥N½X
µ{¦¡½X»P¸ê®Æ¤£¨¬TXT.zip (46.93 KB)
|
|