TOP

Import von NBU-Wechselkursen in Excel (NBU_RATE)

Eine vorgefertigte Funktion für diejenigen, die häufig NBU-Wechselkurse in Excel verwenden müssen. Hilft beim automatischen Einfügen von Währungswerten anhand ihres Codes und Datums von NBU-Website . Den Bankangestellten der Ukraine gewidmet.

Öffnen Sie das Menü Service - Macros - Visual Basic Editor, Setzen Sie das neue Modul ein (Menü Insert - Module) und kopieren Sie den Text dieser Funktion dorthin:

Function NBU_RATE(sCurr$, iiDate As Date)
 'moonexcel.com.ua
 Dim sURI As String
 Dim oHttp As Object
 Dim htmlcode As String
 Dim C As Range
 Dim Q As Long
 Dim iP As Long, z As Long
 Dim S As String, S1 As String, iOnlyTable As String
 Dim b As Object
 Dim massive(30, 5)
 Dim iDatas As Date
 
 sURI = "http://bank.gov.ua/control/uk/curmetal/currency/search?formType=searchFormDate&time_step=daily&date=" & iiDate & "&execute"
 On Error Resume Next
 Set oHttp = CreateObject("MSXML2.XMLHTTP")
 If Err.Number <> 0 Then
 Set oHttp = CreateObject("MSXML.XMLHTTPRequest")
 End If
 If oHttp Is Nothing Then Exit Function
 On Error GoTo ConnectionError
 oHttp.Open "GET", sURI, False
 On Error GoTo ConnectionError
 oHttp.Send
 htmlcode = oHttp.responseText
 iP = InStr(1, htmlcode, "України<"&"br/>встановлює")
 htmlcode = Mid(htmlcode, iP, 10000)
 iP = InStr(1, htmlcode, "<"&"td class=") + 6 + 11 '">
 iDatas = Mid(htmlcode, iP, 10)
 iOnlyTable = Mid(htmlcode, InStr(100, htmlcode, "<"&"table cellpadding="), InStr(1000, htmlcode, "<"&"/table>") - _
 InStr(100, htmlcode, "<"&"table cellpadding=") + 10)'">
 Set Doc = CreateObject("HTMLFile")
 Doc.Write iOnlyTable
 Set b = Doc.all.tags("TABLE")
 
 For Each uTableElement In b
 iRows = uTableElement.Rows.Length
 iCells = uTableElement.Cells.Length
 j = 0
 For k = 1 To iRows
    For l = 1 To 5
        j = j + 1
        massive(k, l) = uTableElement.Cells(j - 1).innerHTML
        If j = uTableElement.Cells.Length Then GoTo 1
    Next l
Next k
1:
 Next uTableElement
 
 For k = 2 To iRows
    For l = 1 To 5
        If massive(k, l) = sCurr Then
            NBU_RATE = Replace(massive(k, 5), ".", ",")
            NBU_RATE = NBU_RATE / massive(k, 3)
        End If
     Next l
Next k

Calculate
NextForLoop:
Set oHttp = Nothing
Exit Function
ConnectionError:
End Function

Schließen Sie Visual Basic Editor und kehren Sie zu Excel zurück.

Jetzt können Sie in Function wizard in der definierten Kategorie User unsere Funktion NBU_RATE finden und verwenden. Die Syntax dieser Funktion lautet wie folgt:

=NBU_RATE ( Währungscode ; Datum )

Wir werden folgendes Ergebnis haben: