¥Î°j°é§ì¸ê®Æ¶V¶]¶VºC¡A¸Ó¦p¦óÄÀ©ñ°O¾ÐÅé?
- ©«¤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 ©ó 2014-6-25 13:39 ½s¿è
¦^´_ 13# sasho
§A쥻ªº Sub °õ¦æ(),¦b§ÚªºPC¨S¦³§A©Ò»¡ªº¶V¨Ó¶VºCªº±¡§Î.³t«×»PMain() ªº°O¿ýÀÉ®t¤£¦h.
¾ã²z¤@¤U,ªþ¤W Sub Main() ªº°O¿ýÀÉ
Ex.rar (10.87 KB)
- Option Explicit
- Dim IE As Object, Query_Sh As Worksheet, CsvPath As String, SaveDate As String
- Dim t As Date, StartTime As Date, °O¿ýÀÉ As String, stockid As Range, spListCount As Integer
- Sub Main()
- Dim i As Integer
- t = Time
- StartTime = Time
- CsvPath = "D:\TSE\"
- ¥Ø¿ý CsvPath
- °O¿ýÀÉ = CsvPath & "Main_Record.TXT"
- If Dir(°O¿ýÀÉ) <> "" Then Kill °O¿ýÀÉ
- ¼È¦s¶ "temp"
- xRecond 0, "µ{¦¡¶}©l°õ¦æ" & vbCrLf
- Set stockid = Sheets("¤u§@ªí1").Range("A2")
- stockid.Parent.Activate
- Do While stockid <> ""
- Application.ScreenUpdating = True
- stockid.Select
- Application.ScreenUpdating = False
- StartTime = Time
- spListCount = ¸ê®Æ¶¼Æ
- If spListCount > 0 Then
- i = i + 1
- xRecond i, stockid & vbTab & "¸ê®Æ¶×¤J"
- ¸ê®Æ¶×¤J
- ¾ã²z
- ¦sÀÉ
- xRecond i, stockid.Value & vbTab & "¦sÀɧ¹²¦ " & Format(Time - StartTime, "¦@SS¬í") & vbCrLf
- End If
- Set stockid = stockid.Offset(1)
- Loop
- IE.Quit
- Application.DisplayAlerts = False
- Query_Sh.Delete
- Application.DisplayAlerts = True
- Workbooks.Open °O¿ýÀÉ
- MsgBox "¦@¦s ""(" & i & ") csvÀɧ¹²¦" & vbTab & "¶O®É " & Format(Time - t, "nn¤Àss¬í")
- End Sub
- Private Sub ¼È¦s¶(temp As String)
- On Error Resume Next
- Set Query_Sh = Sheets(temp)
- If Err.Number = 9 Then
- Sheets.Add(, Sheets(1)).Name = temp
- Set Query_Sh = Sheets(temp)
- End If
- End Sub
- Private Sub ¸ê®Æ¶×¤J()
- Dim strURL As String
- strURL = "URL;" & "http://bsr.twse.com.tw/bshtm/bsContent.aspx?StartNumber=" & stockid & "&FocusIndex=All_" & spListCount
- With Query_Sh
- .UsedRange.Clear
- With .QueryTables.Add(strURL, Query_Sh.[a1])
- .WebFormatting = xlWebFormattingNone
- .WebSelectionType = xlSpecifiedTables
- .WebTables = "5,table2"
- .Refresh 0
- .Delete
- End With
- End With
- End Sub
- Private Sub ¾ã²z()
- Dim i As Integer
- With Sheets("temp")
- SaveDate = Format(.Range("B1"), "YYYYMMDD")
- With .UsedRange.Range("A:A")
- .SpecialCells(xlCellTypeConstants, xlTextValues).EntireRow.Delete
- .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
- End With
- .UsedRange.Columns("F:J").Cut
- .Range("A" & .Rows.Count).End(xlUp).Offset(1).Insert Shift:=xlDown
- .UsedRange.Sort Key1:=.Range("A1"), Order1:=xlAscending, Header:=xlNo
- .UsedRange.Columns("B:B").Insert Shift:=xlToRight
- .UsedRange.Columns(1) = SaveDate
- .UsedRange.Columns(2) = stockid
- For i = 1 To .UsedRange.Rows.Count
- .Cells(i, 3) = Left(.Cells(i, 3), 4)
- .Cells(i, 5) = .Cells(i, 5).Value / 1000
- .Cells(i, 6) = .Cells(i, 6).Value / 1000
- Next
- End With
- End Sub
- Private Sub ¥Ø¿ý(xPath As String)
- Dim SP As Variant, P As String, i As Integer
- SP = Split(xPath, "\")
- P = SP(0)
- With CreateObject("Scripting.FileSystemObject")
- For i = 1 To UBound(SP)
- P = P & "\" & SP(i)
- If .FolderExists(P) = False Then .CreateFolder (P)
- Next
- End With
- End Sub
- Private Sub ¦sÀÉ()
- Dim CSVfolder As String, CSVfile As String
- CSVfolder = CsvPath & SaveDate & "\"
- ¥Ø¿ý CSVfolder
- CSVfile = CSVfolder & stockid & "_" & SaveDate & ".csv"
- If Dir(CSVfile) <> "" Then Kill CSVfile
- Query_Sh.Copy
- With ActiveWorkbook
- .SaveAs Filename:=CSVfile, FileFormat:=xlCSV
- .Close 0
- End With
- End Sub
- Private Sub xRecond(i As Integer, xSub As String)
- Dim S As String
- S = Time & vbTab & Format(Time - t, " ²Änn¤Àss¬í") & vbTab & " ²Ä " & i & " ÓCsvÀÉ " & xSub
- Close #1
- Open °O¿ýÀÉ For Append As #1
- Print #1, S
- Close #1
- Application.StatusBar = S
- End Sub
- Private Function ¸ê®Æ¶¼Æ() As Integer '¨ú±o¶¼Æ
- If IE Is Nothing Then
- Set IE = CreateObject("InternetExplorer.Application")
- IE.Navigate "http://bsr.twse.com.tw/bshtm/bsMenu.aspx"
- IE.Visible = True '¥i¤£Åã¥Ü
- End If
- With IE
- Do: Loop While .Busy Or IE.ReadyState <> 4
- With .document
- .getElementByID("txtTASKNO").Value = stockid
- .getElementByID("btnOK").Click
- Do: Loop While IE.Busy Or IE.ReadyState <> 4 Or .getElementByID("sp_ListCount") Is Nothing
- ¸ê®Æ¶¼Æ = Val(.getElementByID("sp_ListCount").innertext)
- End With
- End With
- End Function
½Æ»s¥N½X |
|
|
|
|
|
|