4

All I did was copy-paste a piece of code that worked perfectly fine in a different sub into my new sub and change the URL I wanted to navigate. The first sub still works, but the second one doesn't. I'm pretty stumped.

Dim ie As InternetExplorer              
Dim html As HTMLDocument                 
Set ie = New InternetExplorer            
ie.Visible = False                       
ie.navigate "http://cesp.hma.eu/Contacts" 
With ie                                  
    Do Until .READYSTATE = 4: DoEvents: Loop
    Do While .Busy: DoEvents: Loop
End With
Set html = ie.document             
Set ie = Nothing                   
Application.StatusBar = ""  

Using F8 to check the code step by step, it seems that the URL ignores the ie.Visible = False (it opens when I reach With ie), then makes the error pop up on Do While .Busy: DoEvents: Loop

I honestly don't know where to start looking to fix this, since I literally only changed the URL and nothing else. My best bet was to just close my workbook and re-open it, but the issue decided to persist. Any hints, explanations, or solutions you can come up with would be greatly appreciated.

Looker
  • 144
  • 1
  • 2
  • 13
  • Have you tried turning it off and on again? – Excel Developers Jul 29 '15 at 15:49
  • Well, I reboot my entire computer, it doesn't look like anything's changed :p Half-jokes aside, I'm not entirely sure what you mean by that. – Looker Jul 29 '15 at 16:05
  • So if you change the URL in the new sub back to what it was in the old sub does it still throw and error? That would be handy to know so you can narrow it down to a website issue or a code issue. – Tim Jul 29 '15 at 16:41
  • Oh, this horribleness plagues me too. My guess is that it's related to security settings in IE. Try Set ie = New InternetExplorerMedium instead. That helped me. – variant Jul 29 '15 at 16:45
  • @Tim - Changing it back to the previous URL made the code work again, so it looks like the problem comes from the page itself. – Looker Jul 30 '15 at 06:30
  • @variant - Your suggestion worked, so thank you! Would you mind posting it an as answer so I can accept it? That said, if you or anyone else happen to know why InternetExplorerMedium worked and just InternetExplorer didn't, I'd greatly appreciate an explanation for that as well. – Looker Jul 30 '15 at 06:32

3 Answers3

6

This is probably related to security settings in IE. As suggested by @Vigneshts88 here, try changing

Set ie = New InternetExplorer 

to:

Set ie = New InternetExplorerMedium

As noted by @Mike in the comment under the answer above, InternetExplorerMedium requires a reference to Microsoft Internet Controls

Community
  • 1
  • 1
variant
  • 1,344
  • 2
  • 11
  • 18
0

Yeah Baby!

Set ie = New InternetExplorerMedium

Fixed it for me!

Can't wait to put this stuff to work.

Steven Alpha
  • 187
  • 1
  • 3
0

This worked for me. I'd been stressing out about trying to get my automation for like 5 hours then tried this. Before I clicked the run, I was thinking it can't be this easy. But it's working. Thank you. I'm saved for now until IE goes away. Hopefully company will keep it around a little longer though. But again, thanks.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 23 '22 at 01:54