返回列表 上一主題 發帖

[發問] 請問如何以VBA擷取網站上的資料?

回復 1# mnsmrtl
不一定要VBA

TOP

回復 4# mnsmrtl
  1. Sub 新增查詢()
  2.     Range("A1") = "2610"   '股票代號
  3.     Range("A3").Select
  4.     With ActiveSheet.QueryTables.Add(Connection:= _
  5.         "URL;http://tw.stock.yahoo.com/q/q?s=" & Range("a1"), Destination:=Selection)  '新增查詢
  6.         .FieldNames = True
  7.         .RowNumbers = False
  8.         .FillAdjacentFormulas = False
  9.         .PreserveFormatting = True
  10.         .RefreshOnFileOpen = False
  11.         .BackgroundQuery = True
  12.         .RefreshStyle = xlInsertDeleteCells
  13.         .SavePassword = False
  14.         .SaveData = True
  15.         .AdjustColumnWidth = True
  16.         .RefreshPeriod = 0
  17.         .WebSelectionType = xlSpecifiedTables
  18.         .WebFormatting = xlWebFormattingNone
  19.         .WebTables = "6"
  20.         .WebPreFormattedTextToColumns = True
  21.         .WebConsecutiveDelimitersAsOne = True
  22.         .WebSingleBlockTextImport = False
  23.         .WebDisableDateRecognition = False
  24.         .WebDisableRedirections = False
  25.         .Refresh BackgroundQuery:=False
  26.         .Name = .ResultRange.Cells(3, 1)
  27.     End With
  28.    End Sub
  29. '***** 已新增後查詢後 可修改A1的股票代號 查詢  *****
  30. Sub 更新查詢()
  31.     With Range("A3").QueryTable
  32.         .Connection = "URL;http://tw.stock.yahoo.com/q/q?s=" & Range("a1") '股票代號在[A1]
  33.         .Refresh BackgroundQuery:=False
  34.         .Name = .ResultRange.Cells(3, 1)
  35.     End With
  36. End Sub
複製代碼

TOP

回復 6# mnsmrtl
另外想再請教,如何只回傳其中一個欄位?
請參考 http://forum.twbts.com/thread-3064-1-2.html

webtables="6",要怎麼取得?




TOP

        靜思自在 : 人生最大的成就是從失敗中站起來。
返回列表 上一主題