ROMaster2
New Member
- Joined
- Dec 12, 2011
- Messages
- 3
Hello!
I've been working as a volunteer for a political group in Washington state and have been trying to write a script that would fetch the voting districts for each address in a table. Normally this would be fairly easy, but when you search for an address in here: http://www5.kingcounty.gov/kcgisreports/dd_report.aspx , the URL generates the parcel number, not the address I enter. I'm trying to figure out how to have excel enter an address on the table to search, copy and paste the page onto excel, paste the values of the voting district, delete the page, and loop onto the next address. If the address doesn't go straight to the page, skip it (so I will do it manually). I used http://www.mrexcel.com/forum/showthread.php?t=534042 to help me along for this. Here's what I have so far:
I'm only using the "226 12TH ST SE" to get it started, which I would fix once it worked.
It debugs at the "UserNameInputBox.Value = cUsername".
Hope that makes any sense, I'd really appreciate any help.
I've been working as a volunteer for a political group in Washington state and have been trying to write a script that would fetch the voting districts for each address in a table. Normally this would be fairly easy, but when you search for an address in here: http://www5.kingcounty.gov/kcgisreports/dd_report.aspx , the URL generates the parcel number, not the address I enter. I'm trying to figure out how to have excel enter an address on the table to search, copy and paste the page onto excel, paste the values of the voting district, delete the page, and loop onto the next address. If the address doesn't go straight to the page, skip it (so I will do it manually). I used http://www.mrexcel.com/forum/showthread.php?t=534042 to help me along for this. Here's what I have so far:
Code:
Sub FetchVotingDistricts()
Const cURL = "http://www5.kingcounty.gov/kcgisreports/dd_report.aspx"
Const cUsername = "226 12TH ST SE"
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Dim qt As QueryTable
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate cURL
'Wait for initial page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
Set doc = IE.Document
'Get the only form on the page
Set LoginForm = doc.forms(0)
'Get the User Name textbox and populate it
Set UserNameInputBox = LoginForm.elements("DistrictsReportControl1$AddressSearch1$txbAddress")
UserNameInputBox.Value = cUsername
'Get the form input button and click it
Set SignInButton = LoginForm.elements("DistrictsReportControl1$AddressSearch1$btnSearch")
SignInButton.Click
'Wait for the new page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
IE.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
IE.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
Range("A3").Select
Selection.Paste
End Sub
It debugs at the "UserNameInputBox.Value = cUsername".
Hope that makes any sense, I'd really appreciate any help.