L
Lyle
I have a UDF named exchangeRate (below):
In a cell I have:
=exchangeRate()
At first entry this updates, refreshes or whatever properly, for
example, to 1.5966.
But on subsequent loads, automatic recalculation, or F9 it does not
update; it remains at 1.5966.
Why not? How can I make it responsive to F9?
(If I change the function to
Public Function exchangeRate@(ByVal vDummy, Optional ByVal vDefault@ =
1.6)
and reference a cell on the spreadsheet with vDummy then updating
seems to take place on each calculation.
I'm hoping there is a less kludgy way.)
**** begin code ****
Public Function exchangeRate@(Optional ByVal vDefault@ = 1.6)
Application.Volatile True
On Error GoTo exchangeRateErr
Dim matches As Object
Dim rawHTML$
Dim regularExpression As Object
Dim xmlHttpRequest As Object
Set regularExpression = CreateObject("VBScript.RegExp")
regularExpression.Pattern = "Euro \(EUR\)<\/td><td
align=""center"" class=""regulartext"">(\d\.\d{0,4})<\/td><td
align=""center"" class=""regulartext"">(\d\.\d{0,4})<\/td>"
Set xmlHttpRequest = CreateObject("Microsoft.XMLHTTP")
xmlHttpRequest.Open "GET", "http://www.rbcroyalbank.com/
RBC:Rc@5fY71A8UAAqnCsxI/rates/cashrates.html", False
xmlHttpRequest.send
rawHTML = xmlHttpRequest.responseText
Set matches = regularExpression.Execute(rawHTML)
exchangeRate = CCur(matches(0).SubMatches(1))
exchangeRateExit:
Exit Function
exchangeRateErr:
With Err
MsgBox .Description _
& vbNewLine & vbNewLine _
& "Exchange Rate defaulted to " & CStr(vDefault), _
vbInformation, _
"Error :" & Err.Number
End With
exchangeRate = vDefault
Resume exchangeRateExit:
End Function
**** end code ****
Note: News clients and/or servers may insert line breaks into code,
resulting in compile errors. These line breaks must be removed.
In a cell I have:
=exchangeRate()
At first entry this updates, refreshes or whatever properly, for
example, to 1.5966.
But on subsequent loads, automatic recalculation, or F9 it does not
update; it remains at 1.5966.
Why not? How can I make it responsive to F9?
(If I change the function to
Public Function exchangeRate@(ByVal vDummy, Optional ByVal vDefault@ =
1.6)
and reference a cell on the spreadsheet with vDummy then updating
seems to take place on each calculation.
I'm hoping there is a less kludgy way.)
**** begin code ****
Public Function exchangeRate@(Optional ByVal vDefault@ = 1.6)
Application.Volatile True
On Error GoTo exchangeRateErr
Dim matches As Object
Dim rawHTML$
Dim regularExpression As Object
Dim xmlHttpRequest As Object
Set regularExpression = CreateObject("VBScript.RegExp")
regularExpression.Pattern = "Euro \(EUR\)<\/td><td
align=""center"" class=""regulartext"">(\d\.\d{0,4})<\/td><td
align=""center"" class=""regulartext"">(\d\.\d{0,4})<\/td>"
Set xmlHttpRequest = CreateObject("Microsoft.XMLHTTP")
xmlHttpRequest.Open "GET", "http://www.rbcroyalbank.com/
RBC:Rc@5fY71A8UAAqnCsxI/rates/cashrates.html", False
xmlHttpRequest.send
rawHTML = xmlHttpRequest.responseText
Set matches = regularExpression.Execute(rawHTML)
exchangeRate = CCur(matches(0).SubMatches(1))
exchangeRateExit:
Exit Function
exchangeRateErr:
With Err
MsgBox .Description _
& vbNewLine & vbNewLine _
& "Exchange Rate defaulted to " & CStr(vDefault), _
vbInformation, _
"Error :" & Err.Number
End With
exchangeRate = vDefault
Resume exchangeRateExit:
End Function
**** end code ****
Note: News clients and/or servers may insert line breaks into code,
resulting in compile errors. These line breaks must be removed.