Salakhetdinov Shamil
mcp2004 at mail.ru
Thu Jun 28 09:12:08 CDT 2012
Hi Darren -- Here is yet another solution cooked here for you and All: Public Function GetCurrencyRate( _ ByVal currencyCode As String, _ Optional ByVal uri = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml") _ As String On Error GoTo HandleErr Dim xdoc As DOMDocument30 Set xdoc = New DOMDocument30 xdoc.async = False xdoc.Load (uri) xdoc.setProperty _ "SelectionLanguage", _ "XPath" xdoc.setProperty _ "SelectionNamespaces", _ "xmlns:gesmes='http://www.gesmes.org/xml/2002-08-01' " + _ "xmlns:mns='http://www.ecb.int/vocabulary/2002-08-01/eurofxref'" Dim xPath As String xPath = Replace("/gesmes:Envelope/mns:Cube/mns:Cube/mns:Cube[@currency='{0}']", _ "{0}", currencyCode) Dim xNode As IXMLDOMNode Set xNode = xdoc.DocumentElement.SelectSingleNode(xPath) Dim xAttr As IXMLDOMNode Set xAttr = xNode.Attributes.getNamedItem("rate") GetCurrencyRate = xAttr.nodeTypedValue Exit Function HandleErr: GetCurrencyRate = "" End Function Public Sub TestMe() ' ' XML & XPath info sources ' ' http://msdn.microsoft.com/en-us/library/aa468547.aspx ' http://msdn.microsoft.com/en-us/library/aa468565 ' http://social.msdn.microsoft.com/Forums/en/xmlandnetfx/thread/a3d6be0c-537a-4467-994a-1e258634ad0c ' http://www.xml.com/pub/a/1999/01/namespaces.html ' http://stackoverflow.com/questions/4550212/parsing-xml-in-vba?rq=1 Dim uri As String Dim currencyCode As String uri = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml" currencyCode = "RUB" Debug.Print currencyCode + "/EUR => " + GetCurrencyRate(currencyCode) End Sub Thank you. -- Shamil Thu, 28 Jun 2012 13:28:15 +1000 от "Darren" <darren at activebilling.com.au>: Wow - That's way cool. Many thanks for the effort Jack, I'm humbled and grateful. Re me adapting it for my needs - Me thinks you assume too much <grin> Again my many thanks for all the effort you've put in. It's very slick. I will be playing with it. Darren <<< skipped>>>