EXCEL实时同步股票价格,只需输入代码,自动显示股价和名称

很多股民在交易时,为了方便对自己的交易行为进行分析和统计,会时常用到股票的“当前价格”,今天给大家提供一个用EXCEL获取股票实时价格的模板。

经过制作后,图表是这样的(如图1)

图1

如果要新加入你自己的股票,启用内容即可(如图2)

图2

为了使用起来方便,我自己加了一个刷新键,填好代码后,直接刷新即可(如图3)


图3

本表使用起来方便,只需要输入红色框内的代码即可,注意好格式就可以了。

下方是代码:

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

最后祝大家投资顺利!

你可能感兴趣的:(EXCEL实时同步股票价格,只需输入代码,自动显示股价和名称)