The problem seems to be that those fields "latlon
" for example, are being populated by some javascript functions which aren't executed until after the page has loaded, so relying on the IE.document.readyState
is not reliable in this instance.
Ordinarily, I say use the WinAPI sleep function (put this at the top of your module):
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Then, do your "waiting" loop like:
Do
Sleep 250
Loop Until IE.ReadyState = READYSTATE_COMPLETE And Not IE.Busy
This was still not working for me for this particular website, though, although if I did Sleep 1000
that seemed to work, the timing will vary based on traffic, network speed, connectivity, available system resources, etc., so even that is not 100% reliable.
I also tried to find a way to emulate the XMLHTTPRequest (which is faster than using the browser directly) but this was also not working.
I looked at the other site. It is possible to fill forms and submit/click controls on a website using VBA, for the most part, but I never found those to be very reliable and didn't try that site.
I spent waaaaay too much time trying to force that solution to work, but it is a bad solution because it's a bad website that's hacked together by some 3rd party using Google's Geocode API.
You should just use Google's API directly
Documentation:
https://developers.google.com/maps/articles/geocodingupgrade
You can construct a URL like:
http://maps.googleapis.com/maps/api/geocode/xml?address=Paris,+France
You can load that to an XML/DOM parser (use a vba reference to Microsoft XML, v6.0 (aka MSXML2) which is what I would recommend. This does not use a browser, it is a stream that is capable of loading an XML from a url (like above) directly in memory.
With a DOM parser, use the DOMDocument's .GetElementsByTagName("location")(0)
and then pull the lat/lon from the child nodes.
Let me know if you have trouble implementing that.