返回列表 上一主題 發帖

如何下載SGX NLT 期貨及選擇權資料

回復 1# chwqk

post的內容太多,改用另一種方法
  1. Sub SGX_NLT_期貨及選擇權資料()
  2.     Dim URL As String, shts As Worksheet
  3.     Dim x As Variant, xi As Integer, A As Object, xlHtm
  4.     Set shts = ActiveSheet '  '("工作表2")
  5.     shts.Cells.Clear
  6.     URL = "http://www.sgx.com/wps/portal/sgxweb/home/marketinfo/derivatives/Nlt"
  7.     With CreateObject("InternetExplorer.Application")
  8.         .Visible = True     '  是否顯示 IE
  9.         .Navigate URL
  10.          Do While .ReadyState <> 4 Or .Busy
  11.                 DoEvents
  12.             Loop
  13.         Application.Wait Now + TimeValue("00:00:06")

  14.         xlHtm = .Document.body.innerHTML                '儲存
  15.         Set A = .Document.getElementsBytagname("table")
  16.         For xi = 116 To 118 Step 2
  17.             .Document.body.innerHTML = A(xi).outerHTML
  18.             .ExecWB 17, 2       '  Select All
  19.             .ExecWB 12, 2       '  Copy selection
  20.             With shts
  21.                 .Range("A" & .[A1048576].End(xlUp).Row + 1).Select
  22.                 .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
  23.             End With
  24.             .Document.body.innerHTML = xlHtm                  '還原
  25.         Next xi
  26.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  27.         .Quit
  28.     End With
  29. End Sub
複製代碼

TOP

回復 3# chwqk

舊版改成

.Range("A" & .[A65535].End(xlUp).Row + 1).Select

TOP

回復 6# chwqk
  1. Sub SGX_NLT_1()
  2.     Dim URL As String, shts As Worksheet
  3.     Dim x As Variant, xi As Integer, A As Object, xlHtm
  4.     Set shts = ActiveSheet '  '("工作表2")
  5.     shts.Cells.Clear
  6.     URL = "http://www.sgx.com/wps/portal/sgxweb/home/marketinfo/derivatives/Nlt"
  7.     With CreateObject("InternetExplorer.Application")
  8.         .Visible = True     '  是否顯示 IE
  9.         .Navigate URL
  10.          Do While .ReadyState <> 4 Or .Busy
  11.                 DoEvents
  12.             Loop
  13.         Application.Wait Now + TimeValue("00:00:06")

  14.         xlHtm = .Document.body.innerHTML                '儲存
  15.         Set A = .Document.getElementsBytagname("table")
  16.         For xi = 74 To 74
  17.             .Document.body.innerHTML = A(xi).outerHTML
  18.             .ExecWB 17, 2       '  Select All
  19.             .ExecWB 12, 2       '  Copy selection
  20.             With shts
  21.                 .Range("A" & .[A1048576].End(xlUp).Row + 1).Select
  22.                 .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
  23.             End With
  24.             .Document.body.innerHTML = xlHtm                  '還原
  25.         Next xi
  26.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  27.         .Quit
  28.     End With
  29. End Sub
複製代碼
  1. Sub SGX_NLT_2()
  2.     Dim URL As String, shts As Worksheet
  3.     Dim x As Variant, xi As Integer, A As Object, xlHtm
  4.     Set shts = ActiveSheet '  '("工作表2")
  5.     shts.Cells.Clear
  6.     URL = "http://www.sgx.com/wps/portal/sgxweb_ch/home/marketinfo/derivatives/Nlt"
  7.     With CreateObject("InternetExplorer.Application")
  8.         .Visible = True     '  是否顯示 IE
  9.         .Navigate URL
  10.          Do While .ReadyState <> 4 Or .Busy
  11.                 DoEvents
  12.             Loop
  13.         Application.Wait Now + TimeValue("00:00:06")

  14.         xlHtm = .Document.body.innerHTML                '儲存
  15.         Set A = .Document.getElementsBytagname("table")
  16.         For xi = 113 To 115 Step 2
  17.             .Document.body.innerHTML = A(xi).outerHTML
  18.             .ExecWB 17, 2       '  Select All
  19.             .ExecWB 12, 2       '  Copy selection
  20.             With shts
  21.                 .Range("A" & .[A1048576].End(xlUp).Row + 1).Select
  22.                 .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
  23.             End With
  24.             .Document.body.innerHTML = xlHtm                  '還原
  25.         Next xi
  26.         shts.Cells.EntireColumn.AutoFit     '  自動調整欄寬
  27.         .Quit
  28.     End With
  29. End Sub
複製代碼

TOP

        靜思自在 : 不怕事多,只怕多事。
返回列表 上一主題