返回列表 上一主題 發帖

想請問excel能每天抓外資期貨的資料嗎

以下的程式碼可以更新
你可以多嘗試看看
我只抓取期交所網站的資料,而期交所在交易日收盤後下午三點更新資料
  1. Sub 台指期OI資料一()
  2. '================================================================================================================================
  3. Dim MyUrl As String
  4. '================================================================================================================================
  5. Application.ScreenUpdating = False  '加快處理速度

  6. Worksheets("Temp").Select          '暫存資料的網頁

  7. Cells.Clear

  8. MyUrl = "URL;http://www.taifex.com.tw/chinese/3/3_1_1.asp"

  9.     With ActiveSheet.QueryTables.Add(Connection:=MyUrl, Destination:=Range("A1"))
  10.         .FieldNames = True
  11.         .RowNumbers = False
  12.         .FillAdjacentFormulas = False
  13.         .PreserveFormatting = True
  14.         .RefreshOnFileOpen = False
  15.         .BackgroundQuery = True
  16.         .RefreshStyle = xlInsertDeleteCells
  17.         .SavePassword = False
  18.         .SaveData = True
  19.         .AdjustColumnWidth = True
  20.         .RefreshPeriod = 0
  21.         .WebSelectionType = xlEntirePage
  22.         .WebFormatting = xlWebFormattingNone
  23.         .WebPreFormattedTextToColumns = True
  24.         .WebConsecutiveDelimitersAsOne = True
  25.         .WebSingleBlockTextImport = False
  26.         .WebDisableDateRecognition = False
  27.         .WebDisableRedirections = False
  28.         .Refresh BackgroundQuery:=False
  29.     End With
  30. '--------------------------------------------------------------------------
  31.    
  32. Bye:
  33. '--------------------------------------------------------------------------
  34. Delete_Rows
  35. '--------------------------------------------------------------------------
  36. End Sub

  37. Private Function Delete_Rows()
  38. '==========================================================================
  39. Dim Temp_Count As Integer
  40. Dim Key_Point As String
  41. Dim Data_Row As Integer
  42. Dim Delete_Row As Integer
  43. Dim I As Integer
  44. '==========================================================================
  45. Temp_Count = Worksheets("Temp").Range("A65536").End(xlUp).Row
  46. '--------------------------------------------------------------------------

  47. StepA:
  48. '--------------------------------------------------------------------------
  49. '找出關鍵字元,判斷所需資料的欄位
  50. '--------------------------------------------------------------------------
  51. For I = 1 To Temp_Count

  52.     Key_Point = Worksheets("Temp").Range("A" & I).Value

  53.     If Key_Point = "臺股期貨 (TX) 行情表" Then
  54.    
  55.         Data_Row = I
  56.         
  57.         GoTo StepB
  58.         
  59.     End If
  60.    
  61. Next I
  62. '--------------------------------------------------------------------------

  63. StepB:
  64. '--------------------------------------------------------------------------
  65. '刪除不必要的資料
  66. '--------------------------------------------------------------------------
  67. Delete_Row = Data_Row - 3

  68. Rows("1:" & Delete_Row).Select

  69. Selection.Delete Shift:=xlUp
  70. '--------------------------------------------------------------------------
  71. End Function
複製代碼

TOP

        靜思自在 : 做好事不能少我一人,做壞事不能多我一人。
返回列表 上一主題