如何将当前价格从网站导入Excel?

时间:2017-10-21 06:09:46

标签: excel web-services bitcoin auto-update stock

目前我在excel中使用它来导入股票价格: enter image description here

这是来自Yahoo Finance并且使用简单,我可以按CTRL-ALT-F9自动更新所有单元格,并以最新价格填充单元格。

如何从其他网站导入更改的号码? 我尝试过使用"数据> Get&转换数据>来自Web"没有成功。

我想要实现的是拥有一个excel单元格,显示http://preev.com/的当前价格,并在按CTRL-ALT-F9时更新最新价格

2 个答案:

答案 0 :(得分:1)

这是UDF写在VBA以返回当前比特硬币现货价格。如上所述,它将使用ctrl-alt-F9进行更新。默认回报是spot价格。它还会使用适当的参数返回buysell

不要忘记设置代码中显示的引用。

在工作表上:

=CurrBitCoinPrice()

常规模块

Option Explicit
'Set Reference to: Microsoft WinHTTP services, Version 5.1
'                  Microsoft VBScript Regular Expressions 5.5

Function CurrBitCoinPrice(Optional BSSp As Long = 3) as Currency
        '1:  Buy
        '2:  Sell
        '3:  Spot

Application.Volatile

    Dim httpRequest As WinHttpRequest
    Dim sResponse(2) As String
    Dim RE As Object, MC As Object
    Dim sType
    Const sInfo As String = "?currency=USD"
    Dim vRes As Variant
    Dim I As Long

sType = Array("buy", "sell", "spot")

Const sUrl As String = "https://api.coinbase.com/v2/prices/"


For I = 0 To 2
Set httpRequest = New WinHttpRequest
With httpRequest
    .Open "Get", sUrl & sType(I) & sInfo
    .Send
    .WaitForResponse

    sResponse(I) = .ResponseText
End With
Set httpRequest = Nothing
Next I

Set RE = New RegExp
With RE
    .Pattern = "\d*\.?\d+"
    .Global = False
End With
ReDim vRes(0 To 1, 1 To 3)
    vRes(0, 1) = "Buy"
    vRes(0, 2) = "Sell"
    vRes(0, 3) = "Spot"

    For I = 0 To 2
        If RE.Test(sResponse(I)) = True Then
            Set MC = RE.Execute(sResponse(I))
            vRes(1, I + 1) = MC(0)
        End If
    Next I

CurrBitCoinPrice = vRes(1, BSSp)

End Function

答案 1 :(得分:0)

我看到了这个解决方案并且看起来与您的问题相同:

excel-convert-external-links-to-values

如果你不喜欢这种方法,我会搜索这种不同的方式