The Gunslinger
Board Regular
- Joined
- Dec 28, 2003
- Messages
- 76
I have a routine which has one simple task of extracting a value from a website, the value is the current UK ISA allowance, from this web site https://www.gov.uk/individual-savings-accounts/overview
the code works a treat, with one small problem, that i only found when i used an adaption of the code to extract other data from a different page, as that code is still a work in progress, i'll post this one, which exhibits the same problem....
once run, it starts a copy of Internet Explorer, not visible as instructed, however, at the end of the code it fails to close it, leaving it orphaned and visible in task manager. I found this problem when i used the code in a loop
here's the code, can someone point out where i've gone wrong please, because right now i can't seem to see the wood for the trees.
for this code, i have also enabled the reference to "Microsoft Internet Controls" in the VBA references dialog
the internet check is also a custom function in another module that works fine
TIA
the code works a treat, with one small problem, that i only found when i used an adaption of the code to extract other data from a different page, as that code is still a work in progress, i'll post this one, which exhibits the same problem....
once run, it starts a copy of Internet Explorer, not visible as instructed, however, at the end of the code it fails to close it, leaving it orphaned and visible in task manager. I found this problem when i used the code in a loop
here's the code, can someone point out where i've gone wrong please, because right now i can't seem to see the wood for the trees.
Code:
Sub Get_ISA_Allowance()
On Error GoTo Skip
If IsInternetConnected() = True Then
Dim Browser As InternetExplorer
Dim Document As HTMLDocument
Dim Elements As IHTMLElementCollection
Dim Element As IHTMLElement
Set Browser = New InternetExplorer
Browser.Visible = False
Browser.Navigate "https://www.gov.uk/individual-savings-accounts/overview"
Do While Browser.Busy And Not Browser.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set Document = Browser.Document
Set Elements = Document.getElementsByTagName("em")
For Each Element In Elements
' Exit null value
If Element.innerText = "" Then GoTo Skip
' Set ISA Allowance cell to new value, stripping out characters first
Sheet1.Range("ISA_Allowance_Total").Value = Format(Element.innerText, "#,##")
Next Element
Skip:
Set Document = Nothing
Set Browser = Nothing
End If
On Error GoTo 0
End Sub
for this code, i have also enabled the reference to "Microsoft Internet Controls" in the VBA references dialog
the internet check is also a custom function in another module that works fine
TIA