My UDF is pulling data from a webpage each time it is called.
The connection is like:
Public Sub myConnection(id)
Set oHtml = New HTMLDocument
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
.Open "GET", "http://www.example.com" & id, False
.send
oHtml.body.innerHTML = .responseText
End With
End Sub
This is pulling stock data and it is working fine, but the workbook becomes very slow when a few hundred UDF calls are made.
My function is like:
Function myFunction(id,element)
Call myConnection(id)
Select Case element
Case "p"
Set dados = oHtml.getElementsByClassName("thisClass")(0)
myFunction = dados.innerText
//etc...
End Select
End Function
Is there a more efficent (faster) way to do this?
I tried storing the pages in some kind of cache. I tried to push the pages into an array but I couldn't write the correct code to get and use the pages in that array.
The array should have 2 dimensions:
- id (page being queried with the stock ticker)
- name, price, beta, etc
I know this isn't very specific but I resarched a lot and couldn't advance any further, so perhaps someone could point some directions or propose a solution.
Thanks in advance.