- ©«¤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
|
¦^´_ 47# GBKEE
·PÁª©¥D@¤ßªº¦^µª¡A¬Ý¤F¤å³¹¤§«á¡A¤j·§¤F¸Ñ¤F¬Û¹ï¤Þ¼ÆªºÃöÁä¦r¡A¤]¦³¸ÕµÛ±N¬Û¹ï¤Þ¼Æ"select"©M"yy"¥N¤J¡Aµ²ªG¬O¥i¦æªº
¤£¹L¦³ÂI°ÝÃD¡G
1.¦b°j°é°õ¦æµ{¦¡®É¬O·|¨Ì·Ó§Ú¦bsheet(3) BÄæ¿é¤Jªº¦~¥÷¶×¤J¤å¦rÀÉ¡A¤£¹L¤U¤@¦~¥÷ªº¸ê®Æ¤S·|Âл\ì¨Óªº¤å¦rÀɤº®e
¨Ò¦p§Ú¦bsheet(3) BÄæ¿é¤Jªº¦~¥÷¬O2014¡B2013¡B2012¡Aµ²ªG2014ªº¼g§¹«á¦A¼g¤U¤@µ§ªº2013´N·|§âì¨Ó¼g¤Jªº2014Âл\±¼
¤£ª¾¹D¯à¤£¯à±N¤T¦~ªº¸ê®Æ³£¼g¤J¤å¦rÀÉ¡H
2.¦~¥÷°j°é¬O§_¥u¯à§Q¥Î¹³ÓªÑ¥N¸¹¤@¼Ë¦bsheet(3) ¬YÄæ¿é¤J·QnÂ^¨úªº¦~¥÷¸ê®Æ¡A¯à¤£¯àª½±µ¼g¤JVBA¤¤©O¡H
3.¼g¤Jªº¤å¦rÀɬO±q¶}©l¦³¼Æ¦r¸ê®Æ®É¼g°_¡A¤£ª¾¹D¯à¤£¯à¥Ñ³Ì¤W¤èӪѥN¸¹¨º¤@¦C¶}©l¼g¤J¡A¤]´N¬O¤å¦rÀɤ¤·|¬Ý±o¨ìӪѥN¸¹
4.¦]¬°³oÓVBAµ{¦¡¬Oª½±µ±N¸ê®Æ¼g¤J¤å¦rÀÉ¡AµLªk¬Ý¨ì¸ê®Æ¶×¤JEXCELªº°Ê§@¡A¤£ª¾¹D¯à¤£¯à°µ¤é´Á±Æ§Ç
¨Ò¦p¼g¤Jªº²Ä¤@¦~¥÷¸ê®Æ¥Ñ¤W¨ì¤U¬O103¦~1¤ë¥÷¨ì103¦~5¤ë¥÷¡A¤£ª¾¹D¯à¤£¯à±N5¤ë¥÷¼g¨ì³Ì¤W¤è
§Ú·Q°ÝÃD·|³o»ò¦h¡AÀ³¸Ó¬O§ÚVBA°ò¦ÁÙ¨S¥´¦n´N«æ©ó¾Ç²ß§ó¶i¶¥ªºªF¦è¡A¬Ý¨Ó§Ú¥i¯à±o¦h¬Ý¨Ç®Ñ¡B¤å³¹¡B¼v¤ù¥R¹ê¦Û¤vªºVBA°ò¦¡A«Ü·PÁª©¥D³s¤é¨Ó¤£¹½¨ä·Ðªº¦^µª¡I
- 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/st44.php"
- ' .Visible = True '¤£Åã¥Üie
- Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
- End With
- End Sub
- Sub ¤WÂd¤ë¦¨¥æ¸ê°T()
- Dim E, X As Range, xPath As String, xFile As String, A, B As Object, fs As Object, F As Object, IE_URL As String
- Dim i As Integer, ii As Integer, t As Date, AR(), Rng, Rng1 As Range, r, C, S
- Set fs = CreateObject("Scripting.FileSystemObject")
- IE_URL = "http://www.gretai.org.tw/ch/stock/statistics/monthly/st44.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")
- 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 = "D:\°]³ø¸ê®Æ"
- IE_Application '
- Application.StatusBar = " "
- For Each E In Rng
- For Each X In Rng1
- With IE
- Set B = .document.getelementsbytagname("select")("yy")
- B.Value = X
- 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 & "\HPM.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 C
- .WriteLine S
- Next i
- .Close
- End With
- ii = ii + 1
- End With
- Application.StatusBar = Application.Text(Time - t, ["MM¤ÀSS¬í"]) & " ¦@¶×¤J¤WÂd¤ë¦¨¥æ " & ii & " ¤å¦rÀÉ"
- Next X
- Next E
- 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
test2.zip (17.73 KB)
|
|