返回列表 上一主題 發帖

Web 資料 匯入 問題

回復 2# seemee
  1. Sub 個股交易明細下載()
  2.     Dim 股票代號 As String, 年 As String, 月 As String, N As Name, i As Integer, T As Integer, A
  3.     年 = 2013
  4.     月 = 1
  5.     月 = Format(月, "00")
  6.     股票代號 = 2330
  7.    
  8.     T = Time
  9.     With ActiveSheet
  10.         .Cells.Clear
  11.         DoEvents
  12.         'Application.ScreenUpdating = False
  13.         'Application.StatusBar = False
  14.         With .QueryTables.Add(Connection:="URL;http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/genpage/Report" & 年 & 月 & "/" & 年 & 月 & "_F3_1_8_" & 股票代號 & ".php?STK_NO=" & 股票代號 & "&myear=" & 年 & "&mmon=" & 月, Destination:=Range("A1"))
  15.             .BackgroundQuery = True
  16.             .WebTables = "8"
  17.             .Refresh BackgroundQuery:=False
  18.             ActiveSheet.Names(.Name).Delete
  19.         End With
  20.         月 = 2
  21.         
  22.         Do
  23.              月 = Format(月, "00")
  24.             .Cells(.Rows.Count, 1).End(xlUp).Offset(1).Select
  25.             With .QueryTables.Add(Connection:="URL;http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/genpage/Report" & 年 & 月 & "/" & 年 & 月 & "_F3_1_8_" & 股票代號 & ".php?STK_NO=" & 股票代號 & "&myear=" & 年 & "&mmon=" & 月, Destination:=Selection)
  26.                 .BackgroundQuery = True
  27.                 .WebTables = "8"
  28.                 On Error Resume Next
  29.                 Do
  30.                      Err.Clear
  31.                 .Refresh BackgroundQuery:=False
  32.                 If Err.Number = 1004 Then GoTo 10 '無法開啟檔案就跳到下一月
  33.                 Loop Until Err.Number = 0
  34.                 On Error GoTo 0
  35.                 If Application.CountA(.ResultRange) = 0 Then GoTo OUT
  36.                 .ResultRange.Rows("1:2").Delete '刪除1:2列
  37.                 ActiveSheet.Names(.Name).Delete
  38. 10
  39.                 月 = 月 + 1
  40.             End With
  41.         Loop Until 月 > 12
  42. OUT:
  43.         .[A1].Select
  44.         Application.ScreenUpdating = True
  45.         With .UsedRange
  46.             .WrapText = False
  47.             .Interior.ColorIndex = xlNone
  48.             .Font.Size = 12
  49.             .Columns.AutoFit
  50.             A = CreateObject("WScript.Shell").popup("共下載 " & i & " 頁費時  " & Format(Time - T, "hh:mm分SS秒"), 5, 年 & "_" & 股票代號, 48 + 0)
  51.             Application.StatusBar = 年 & " _ " & 股票代號 & " 共下載 " & i & "頁 費時 " & Format(Time - T, "HH:MM:SS")
  52.         End With
  53.         For Each N In .Names
  54.             N.Delete
  55.         Next
  56.      End With
  57. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 時時好心就是時時好日。
返回列表 上一主題