Dim IE as New InternetExplorer
IE.Visible = True
IE.Navigate(\"http://www.google.com\")
Do Until IE.Busy = False
Loop
IE.document.getElementsByTagName(\"Input\")(
The solution of resetting the HTMLDocument Object works for me too i.e.
'After Page Loads, Reset HTMLDocument Object and Wait 1 Second Before recreating It
Set html = Nothing
Application.Wait Now + TimeValue("0:00:01") '<<< This seems to really help
Set html = IE.document
None of the other solutions have solved my problem.
After testing all above suggested fixes and even more, I am positive this is a weird bug with Eventhandling of child Processes invoked by IE whenever there are different security zones on one website.
Cut to the chase, here is the solution:
'Craziest workaround ever due to bugged IE Eventhandling
Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop
Add this code piece every time after navigating to a new page or other events that might cause the website to reload, like clicking on a submit button or similar.
Dan above suggested to add DoEvents statements liberally in your code, which did not 100% do the trick for me. Instead, I suggest to add above code whereever applicable.
Kudos to Dan, without your comment I would've never figured it out!
Short summary of the BENEFITS this method has over other suggested fixes:
Summary of all the things YOU DO NOT NEED with this approach:
I'm only including above summary because I've seen all those workarounds suggested and have personally tried them with no luck so far.
Example code based on OP's question:
Dim IE as Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate("http://www.google.com")
'Craziest workaround ever due to bugged IE Eventhandling
Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop
IE.document.getElementsByTagName("Input")(3).Value = "Search Term"
IE.document.Forms(0).Submit ' this previously crashed
I really hope this will help others in the future. Godspeed to everyone who helped with piecing the solution together.
Best Regards Patrick