0

I'm working on a longer script for Access and at one point it is necessary to check a webservice for the latest version of a file (the filename). This webservice is only accessible via a browser where it is necessary to athenticate. I already managed to open an Internet Explorer window (which is visible although it shouldn't). However after that I get the error

Method 'Busy' of object 'IWebBrowser2' failed

Right now I have the following code:

Dim appIE As Object
Dim sURL as String, infoStr as String
Set appIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}") 'class id of InternetExplorerMedium
sURL = "https://webservice.example.com:1234/Server/test.jsp?parameter=value"
With appIE
    .Navigate sURL, Headers:=CreateBasicAuthHeader("MyUsername", "MyPassword")
    .Visible = False
End With

Do While appIE.Busy Or appIE.ReadyState <> 4
    DoEvents
Loop

infoStr = appIE.Document.getElementsByTagName("body").item.innerText

which works well until the line:

Do While appIE.Busy Or appIE.ReadyState <> 4

If I'd leave the loop out the same error would appear but for 'Document' instead of 'Busy' in line infoStr = appIE.Document.getElementsByTagName("body").item.innerText. Considering that also .Visible = False has no impact (I can see the browser window) I think that any operation on appIE after .Navigate isn't working. But I have no idea why.

After searching a while after the mentioned error I found 3 possible solutions but neither of them succeed.

  1. Using the .Busy or .ReadyState properties to prevent the macro from proceeding while the browser hasn't completely loaded the site. Which I obviously already do.
  2. Using internet explorer at a medium integrity level. Which I also already do.
  3. Searching the Task Manager for any "orphaned" IE processes. There are none.

Any help or idea is greatly appreciated.

Ruvox
  • 116
  • 1
  • 10
  • Personally, as a full workaround, I tend to use a form with a webbrowser control instead of `GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")`. That way, I'm 100% sure that I can always get a reference to the Internet Explorer Application object, it looks more integrated in the Access application, and I can hide, show and resize it more reliably. – Erik A Jan 24 '19 at 16:14
  • I can understand that but since the only purpose of my macro at this point is to check the currency of a file (get its filename) I see no point of giving the user a control where he has to do something he don't know about for a reason he don't even know about. – Ruvox Jan 24 '19 at 16:21
  • 1
    If you're not actually using IE automation (e.g. tasks where you need javascript to run, need to work with cookies, etc.) then you should use either WinHTTP or MSXML, not IE automation, that's both more reliable and faster, you could just synchronously retrieve the page (no .busy or readystate stuff). Also, the form I use is invisible 99% of the time. It's just way easier to reliably work with a WebBrowser control on a form than to reliably work with an InternetExplorer application object that's not associated with your application. – Erik A Jan 24 '19 at 16:27
  • What's the advantage of doing this instead of `CreateObject("InternetExplorer.Application")`? With this, I have been very successful using internet explorer automation, including the use of ie.busy – HMVBA Jan 24 '19 at 16:35
  • @ErikvonAsmuth I will maybe try this tomorrow thanks for the suggestion. – Ruvox Jan 24 '19 at 16:39
  • @HMVBA As mentioned it was recommended to use this to avoid the error I'm currently facing for example here: https://stackoverflow.com/questions/30086425/excel-vba-method-document-of-object-iwebbrowser2-failed It's necessary due to my local intranet – Ruvox Jan 24 '19 at 16:42
  • Ah, yes. That makes sense. You might take a look at https://stackoverflow.com/questions/12965032/excel-vba-controlling-ie-local-intranet at Anup Upadhyay's solution if you can't use WinHTTP as Erik von Asmuth suggests – HMVBA Jan 24 '19 at 17:02
  • Try to disable the protected mode for testing purpose to check whether it to solve the error or not. – Deepak-MSFT Jan 25 '19 at 09:48

0 Answers0