TOP

Import of exchange rates from the NBU website to LibreOffice Calc

A ready-made function for those who often have to use NBU exchange rates in LibreOffice Calc.

It helps to automatically obtain the value of the currency exchange rate from the NBU website by its code and date.



BASIC code for the NBU_RATE function

To add the function of importing NBU exchange rates, open the menu Tools - Macros - Edit Macros..., select Module1 and copy the following text into this module:

Function NBU_RATE(ByVal pCurrency, ByVal pDate)
  'moonexcel.com.ua 
  Dim FCalc As Object
  
  If Len(pCurrency) = 0 Or Len(pDate) = 0 Then Exit Function             
      
  FCalc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
  
  tDate = FCalc.callFunction("TEXT", Array(pDate,"YYYYMMDD"))
                                                    
  RequestString = "https://bank.gov.ua/NBU_Exchange/exchange_site?start=" & tDate & "&end=" & tDate & "&valcode=" & pCurrency
            
  WebServiceResponse = FCalc.callFunction("WEBSERVICE", Array(RequestString))  
  
  NBU_RATE = FCalc.callFunction("FILTERXML", Array(WebServiceResponse,"//rate_per_unit"))    
End Function

Close Macro Editor and return to LibreOffice Calc.

Now you can manually enter our NBU_RATE() function. The syntax of this function is as follows:

=NBU_RATE (currency code; date)

We will have the following result: