- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
9#
發表於 2016-9-9 14:28
| 只看該作者
回復 8# bioleon69
試試看- Option Explicit
- Private Sub CommandButton1_Click()
- Dim strURL$ '宣告strURL為變數
- strURL = "https://tw.stock.yahoo.com/d/s/dividend_" & [A1].Value & ".html" '定義strURL變數內容
- [A3].CurrentRegion = "" '清除文字沒清除格式(美化好的表格)
- With ActiveSheet.QueryTables.Add("url;" & strURL, Range("a3"))
- .WebFormatting = xlWebFormattingNone '(NONE)不包含格式,(ALL)包含格式
- .WebSelectionType = xlSpecifiedTables '指定table表格模式
- .WebTables = "8" '第8個table表格
- On Error Resume Next
- .Refresh False
- [B1] = ""
- If Err <> 0 Then
- [B1] = "請輸入正確股票代號"
- Else
- '**********************************
- '"欄寬"是否可以實現如同文字顏色背景一樣,能夠自適應?
- '請錄製巨集後套用程式碼在此
- '*****************************'
- [B1] = 網頁(strURL) '填上股票名稱代號
- End If
- End With
- End Sub
- Private Function 網頁(Surl As String) As String
- Dim oXmlhttp As Object, oHtmldoc As Object
- Set oXmlhttp = CreateObject("msxml2.xmlhttp")
- Set oHtmldoc = CreateObject("htmlfile")
- With oXmlhttp
- .Open "Get", Surl, False
- .Send
- oHtmldoc.write .responseText
- End With
- 網頁 = Split(oHtmldoc.Title, "-")(0)
- End Function
複製代碼 |
|