返回列表 上一主題 發帖

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

版主大大你好:
       
   小弟對透過EXCEL取得網頁資料,
一直深深感到興趣但是無法領會及突破困境。
   現想借用此板及板主大大提供的語法。
並取得此網頁的指定位置內容如下:

一、
   網址:http://tw.stock.yahoo.com/d/s/company_1102.html

二、
   取得此網頁的資料表為

獲 利 能 力 (100第2季) 最新四季每股盈餘  最近四年每股盈餘

三、
  小弟有試著直接將下列語法的網址更正
如上的網址但是無法成功。
能請版主大大指點小弟。

感恩大大:


Sub 新增查詢()
    Range("A1") = "2610"   '股票代號
    Range("A3").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://tw.stock.yahoo.com/q/q?s=" & Range("a1"), Destination:=Selection)  '新增查詢
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "6"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
        .Name = .ResultRange.Cells(3, 1)
    End With
   End Sub
'***** 已新增後查詢後 可修改A1的股票代號 查詢  *****
Sub 更新查詢()
    With Range("A3").QueryTable
        .Connection = "URL;http://tw.stock.yahoo.com/q/q?s=" & Range("a1") '股票代號在[A1]
        .Refresh BackgroundQuery:=False
        .Name = .ResultRange.Cells(3, 1)
    End With
End Sub

TOP

謝謝oobird版主大大。
感謝您幫小弟開啟這一扇大門,
同時也幫小弟搬開心中的一塊
大石頭。
一語點醒如此好用的EXCEL
錄製功能,小弟卻將它遺忘。

另小弟想宣告設定
DIM qtQtrResults AS ......
才能讓它在WITH qtQtrResults時
能顯示出其屬性及功能呢?
With qtQtrResults
    .WebFormatting = xlNone
    .WebSelectionType = xlSpecifiedTables
    .WebTables = "9"
    .Refresh
End With

感恩大大!

TOP

謝謝oobird版主大大。
感謝您引領小弟進入
另一個新的領域。

感恩大大!

TOP

        靜思自在 : 愛不是要求對方,而是要由自身的付出。
返回列表 上一主題