返回列表 上一主題 發帖

載入歷年股利政策

回復 1# pupai
試試看
  1. Option Explicit
  2. Const 資訊 = "個股資訊"
  3. Const 主表 = "查詢表"
  4. Sub 載入全部數據()
  5.     Dim Rng As Range, e As Range
  6.     With Sheets(主表)
  7.         .Range(.[a4], .[a4].End(xlDown)).Offset(, 1).Resize(, 11) = ""
  8.         For Each e In .Range(.[a4], .[a4].End(xlDown))
  9.             數據 e
  10.         Next
  11.      End With
  12. End Sub
  13. Sub 載入個股數據()
  14.     數據 ActiveCell
  15.     ActiveCell.Resize(, 12).Select
  16. End Sub
  17. Private Sub 數據(xRng As Range)
  18.     Dim xUrl As String
  19.      If xRng.Parent.Name <> 主表 Then MsgBox "請選擇 " & 主表 & " 的個股編號 範圍  ": Exit Sub
  20.      With Sheets(主表)
  21.         If Intersect(.Range(.[a4], .[a4].End(xlDown)), xRng) Is Nothing Then MsgBox "請選擇 " & 主表 & " 的個股編號 範圍  ": Exit Sub
  22.     End With
  23.     xUrl = "URL;http://tw.stock.yahoo.com/d/s/dividend_" & xRng & ".html"
  24.     With Sheets(資訊)
  25.         If .QueryTables.Count <> 0 Then
  26.             .QueryTables(1).Connection = xUrl
  27.         Else
  28.         .QueryTables.Add xUrl, .[A1]
  29.         End If
  30.         With .QueryTables(1)
  31.             .WebSelectionType = xlSpecifiedTables
  32.             .WebTables = "7,10"
  33.             .Refresh BackgroundQuery:=False
  34.             xRng.Cells(1, 2) = Replace(Split(.ResultRange.Cells(1, 1), " ")(0), xRng, "")
  35.             xRng.Cells(1, 3).Resize(, 10) = Application.WorksheetFunction.Transpose(.ResultRange.Cells(6, 6).Resize(10))
  36.             xRng.Cells(1, 3).Resize(, 10).NumberFormatLocal = "G/通用格式"
  37.         End With
  38.     End With
  39.     Beep
  40. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 唯其尊重自己的人,才更勇於縮小自己。
返回列表 上一主題