很多股民在交易時(shí),為了方便對(duì)自己的交易行為進(jìn)行分析和統(tǒng)計(jì),會(huì)時(shí)常用到股票的“當(dāng)前價(jià)格”胰默,今天給大家提供一個(gè)用EXCEL獲取股票實(shí)時(shí)價(jià)格的模板漏隐。
經(jīng)過制作后,圖表是這樣的(如圖1)
如果要新加入你自己的股票奴迅,啟用內(nèi)容即可(如圖2)
為了使用起來方便青责,我自己加了一個(gè)刷新鍵,填好代碼后,直接刷新即可(如圖3)
本表使用起來方便脖隶,只需要輸入紅色框內(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:
最后祝大家投資順利产阱!