EXCEL實(shí)時(shí)同步股票價(jià)格,只需輸入代碼,自動(dòng)顯示股價(jià)和名稱

很多股民在交易時(shí),為了方便對(duì)自己的交易行為進(jìn)行分析和統(tǒng)計(jì),會(huì)時(shí)常用到股票的“當(dāng)前價(jià)格”,今天給大家提供一個(gè)用EXCEL獲取股票實(shí)時(shí)價(jià)格的模板。

經(jīng)過(guò)制作后,圖表是這樣的(如圖1)

圖1

如果要新加入你自己的股票,啟用內(nèi)容即可(如圖2)

圖2

為了使用起來(lái)方便,我自己加了一個(gè)刷新鍵,填好代碼后,直接刷新即可(如圖3)


圖3

本表使用起來(lái)方便,只需要輸入紅色框內(nèi)的代碼即可,注意好格式就可以了。

下方是代碼:

Sub GetData()

? ? Dim succeeded As Integer

? ? Dim url As String

? ? Dim row As Integer

? ? Dim code As String

? ? Dim dateStr As String

? ? Dim cash As String

? ? Dim current As String

? ? Dim firstCode As String

? ? Dim secondCode As String

? ? current = Date

? ? Dim currentRow As Integer

? ? currentRow = 0

? ? Dim zhangDie As Double

? ? Dim isSet As Boolean


? ? For row = 2 To Range("A1").CurrentRegion.Rows.Count

? ? ? ? code = Cells(row, 1).Value

? ? ? ? succeeded = 0


? ? ? ? If code <> "" Then

? ? ? ? ? ? firstCode = LCase(Mid(code, 1, 1))

? ? ? ? ? ? secondCode = LCase(Mid(code, 2, 1))


? ? ? ? ? ? If firstCode = "s" And secondCode = "h" Then

? ? ? ? ? ? ? ? url = "http://qt.gtimg.cn/q=" & Cells(row, 1).Value

? ? ? ? ? ? ? ? succeeded = FillOneRow(url, row)

? ? ? ? ? ? ElseIf firstCode = "s" And secondCode = "z" Then

? ? ? ? ? ? ? ? url = "http://qt.gtimg.cn/q=" & Cells(row, 1).Value

? ? ? ? ? ? ? ? succeeded = FillOneRow(url, row)

? ? ? ? ? ? Else

? ? ? ? ? ? ? ? If firstCode <> "0" Then

? ? ? ? ? ? ? ? ? ? url = "http://qt.gtimg.cn/q=sh" & Cells(row, 1).Value

? ? ? ? ? ? ? ? ? ? succeeded = FillOneRow(url, row)

? ? ? ? ? ? ? ? End If


? ? ? ? ? ? ? ? If succeeded = 0 Then

? ? ? ? ? ? ? ? ? ? url = "http://qt.gtimg.cn/q=sz" & Cells(row, 1).Value

? ? ? ? ? ? ? ? ? ? succeeded = FillOneRow(url, row)

? ? ? ? ? ? ? ? End If

? ? ? ? ? ? End If


? ? ? ? ? ? If succeeded = 0 Then

? ? ? ? ? ? ? ? MsgBox ("獲取失敗")

? ? ? ? ? ? End If

? ? ? ? End If

? ? Next

End Sub

然后在Thisworkbook下輸入以下代碼:

Private Sub Workbook_Open()

Call Sheet1.GetData

End Sub

如圖4:

圖4

最后祝大家投資順利!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容