- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 1# pupai
試試看- Option Explicit
- Const 資訊 = "個股資訊"
- Const 主表 = "查詢表"
- Sub 載入全部數據()
- Dim Rng As Range, e As Range
- With Sheets(主表)
- .Range(.[a4], .[a4].End(xlDown)).Offset(, 1).Resize(, 11) = ""
- For Each e In .Range(.[a4], .[a4].End(xlDown))
- 數據 e
- Next
- End With
- End Sub
- Sub 載入個股數據()
- 數據 ActiveCell
- ActiveCell.Resize(, 12).Select
- End Sub
- Private Sub 數據(xRng As Range)
- Dim xUrl As String
- If xRng.Parent.Name <> 主表 Then MsgBox "請選擇 " & 主表 & " 的個股編號 範圍 ": Exit Sub
- With Sheets(主表)
- If Intersect(.Range(.[a4], .[a4].End(xlDown)), xRng) Is Nothing Then MsgBox "請選擇 " & 主表 & " 的個股編號 範圍 ": Exit Sub
- End With
- xUrl = "URL;http://tw.stock.yahoo.com/d/s/dividend_" & xRng & ".html"
- With Sheets(資訊)
- If .QueryTables.Count <> 0 Then
- .QueryTables(1).Connection = xUrl
- Else
- .QueryTables.Add xUrl, .[A1]
- End If
- With .QueryTables(1)
- .WebSelectionType = xlSpecifiedTables
- .WebTables = "7,10"
- .Refresh BackgroundQuery:=False
- xRng.Cells(1, 2) = Replace(Split(.ResultRange.Cells(1, 1), " ")(0), xRng, "")
- xRng.Cells(1, 3).Resize(, 10) = Application.WorksheetFunction.Transpose(.ResultRange.Cells(6, 6).Resize(10))
- xRng.Cells(1, 3).Resize(, 10).NumberFormatLocal = "G/通用格式"
- End With
- End With
- Beep
- End Sub
複製代碼 |
|