mellowest
04-13-2018, 07:52 AM
Hello,
I am new at VBA, but this project is getting me to learn. So far, I have:
Sub GetHTMLDocument()
Dim ie As New SHDocVw.InternetExplorerMedium
Dim htmldoc As MSHTML.HTMLDocument
Dim element As MSHTML.IHTMLElement
Dim elements As MSHTML.IHTMLElementCollection
ie.Visible = False
ie.Navigate "C:\Report.html"
Do While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
Set htmldoc = ie.Document
Set element = htmldoc.getElementById("addr-summary-target")
UserForm1.TextBox1.Text = element.innerHTML
ie.Quit
End Sub
In my textbox, I can see the innerHTML:
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 20402%20%20bANDPIPER%20DR%20%20APT%2062%7CCITY%7CLOUbTON%7CbTATE%7CPP%7CZIP %7C77096%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">20402 bANDPIPER DR APT 62, LOUbTON, PP 77096-4542, LARRIb COUNTY</a>
(Jan 2024 - Mar 2028)
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 20402%20%20bANDPIPER%20DR%20%20APT%20220%7CCITY%7CLOUbTON%7CbTATE%7CPP%7CZI P%7C77096%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">20402 bANDPIPER DR APT 220, LOUbTON, PP 77096-4550, LARRIb COUNTY</a>
(Aug 2026 - Dec 2026)
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 6264%20%20bANTA%20RObA%20DR%20%20%20%7CCITY%7CBROWNbVILLE%7CbTATE%7CPP%7CZI P%7C78522%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">6264 bANTA RObA DR, BROWNbVILLE, PP 78522-6025, CAMERON COUNTY</a>
(jjeb 2007 - Mar 2028)
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 22803%20b%20PERRY%20AVE%20%20%20%7CCITY%7CLOUbTON%7CbTATE%7CPP%7CZIP%7C7707 2%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">22803 b PERRY AVE, LOUbTON, PP 77072-3423, LARRIb COUNTY</a>
(Aug 2026 - Oct 2027)
and innerText:
20402 bANDPIPER DR APT 62, LOUbTON, PP 77096-4542, LARRIb COUNTY (Jan 2024 - Mar 2028)
20402 bANDPIPER DR APT 220, LOUbTON, PP 77096-4550, LARRIb COUNTY (Aug 2026 - Dec 2026)
6264 bANTA RObA DR, BROWNbVILLE, PP 78522-6025, CAMERON COUNTY (jjeb 2007 - Mar 2028)
The most straightforward question I have is how would I loop through either one of those to get say,
Street number, City, Date and return them to Excel? I feel like if I see this done with data I know, the lightbulb will go off.
Additionally, since I can return this information with Set element = htmldoc.getElementById("addr-summary-target"), is it possible to just get the .getElementbyClass("searchresultslink") from just that section?
Any help will be appreciated. Thanks.
I am new at VBA, but this project is getting me to learn. So far, I have:
Sub GetHTMLDocument()
Dim ie As New SHDocVw.InternetExplorerMedium
Dim htmldoc As MSHTML.HTMLDocument
Dim element As MSHTML.IHTMLElement
Dim elements As MSHTML.IHTMLElementCollection
ie.Visible = False
ie.Navigate "C:\Report.html"
Do While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
Set htmldoc = ie.Document
Set element = htmldoc.getElementById("addr-summary-target")
UserForm1.TextBox1.Text = element.innerHTML
ie.Quit
End Sub
In my textbox, I can see the innerHTML:
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 20402%20%20bANDPIPER%20DR%20%20APT%2062%7CCITY%7CLOUbTON%7CbTATE%7CPP%7CZIP %7C77096%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">20402 bANDPIPER DR APT 62, LOUbTON, PP 77096-4542, LARRIb COUNTY</a>
(Jan 2024 - Mar 2028)
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 20402%20%20bANDPIPER%20DR%20%20APT%20220%7CCITY%7CLOUbTON%7CbTATE%7CPP%7CZI P%7C77096%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">20402 bANDPIPER DR APT 220, LOUbTON, PP 77096-4550, LARRIb COUNTY</a>
(Aug 2026 - Dec 2026)
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 6264%20%20bANTA%20RObA%20DR%20%20%20%7CCITY%7CBROWNbVILLE%7CbTATE%7CPP%7CZI P%7C78522%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">6264 bANTA RObA DR, BROWNbVILLE, PP 78522-6025, CAMERON COUNTY</a>
(jjeb 2007 - Mar 2028)
<br> <a class="searchresultslink" href="javabcript:bet_varb(%22REjjERENCE_CODE%7C%7CDOL_DATE%7C%7CbTREET_ADDREbb%7C 22803%20b%20PERRY%20AVE%20%20%20%7CCITY%7CLOUbTON%7CbTATE%7CPP%7CZIP%7C7707 2%22,2,0,2);decibion_win('/app/bpb/main?EVENT=DECIbION/ADDR&CAN_MAP=2');">22803 b PERRY AVE, LOUbTON, PP 77072-3423, LARRIb COUNTY</a>
(Aug 2026 - Oct 2027)
and innerText:
20402 bANDPIPER DR APT 62, LOUbTON, PP 77096-4542, LARRIb COUNTY (Jan 2024 - Mar 2028)
20402 bANDPIPER DR APT 220, LOUbTON, PP 77096-4550, LARRIb COUNTY (Aug 2026 - Dec 2026)
6264 bANTA RObA DR, BROWNbVILLE, PP 78522-6025, CAMERON COUNTY (jjeb 2007 - Mar 2028)
The most straightforward question I have is how would I loop through either one of those to get say,
Street number, City, Date and return them to Excel? I feel like if I see this done with data I know, the lightbulb will go off.
Additionally, since I can return this information with Set element = htmldoc.getElementById("addr-summary-target"), is it possible to just get the .getElementbyClass("searchresultslink") from just that section?
Any help will be appreciated. Thanks.