1

I have a problem with extracting data from the website using VBA on Citrix Virtual Desktop.

I have wrote my code on my local desktop first and it works good - HTML source has been extracted to the cell in Excel. On VDI IE opens the website without any problems.

Code:

Sub GetBody()
Dim Body As String
the_start:

Set ObjIE = CreateObject("InternetExplorer.Application")
ObjIE.Visible = False

ObjIE.navigate ("https://pl.wikipedia.org/wiki/Wikipedia:Strona_g%C5%82%C3%B3wna")

    Do
    DoEvents

        If Err.Number <> 0 Then
            ObjIE.Quit
            Set ObjIE = Nothing
        GoTo the_start:
        End If

    Loop Until ObjIE.readyState = 4

    Body = ObjIE.document.Body.innerHTML
    Cells(1, 1).Value = Body

End Sub

When I try to run this code on VDI I am getting following error:

Run-time error '-2147467259(80004005)': Method 'Document' of object 'IWebBrowser2' failed.

Any ideas where this error comes from and what I should add to run it successfully on VDI?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Hlostu
  • 21
  • 2
  • Just out of curiosity, what is the version of IE in the virtual machine? – Yane Apr 23 '19 at 07:34
  • @Yane Version : 11.0.9600.19326 same as on my local computer – Hlostu Apr 23 '19 at 07:43
  • Which line throws the error? I suspect its: `Body = ObjIE.document.Body.innerHTML`? – Zac Apr 23 '19 at 08:18
  • Also, you have potential endless loop there: when you first get into the `Do` loop, if your error is not 0, you are using `Goto` to step out of the loop and then come back into the loop without ever resetting the `err` value. So once the `err` value is not 0, you have an endless loop – Zac Apr 23 '19 at 08:22
  • @Zac yup - in this line – Hlostu Apr 23 '19 at 08:29
  • Can you step through and check if `objIE` is set properly – Zac Apr 23 '19 at 08:55
  • @Hlostu, I try to make a test with your code and find that your code is working fine on my side. It can be possible that your Internet Explorer get disconnected and raise this error. You can try to make a test with this code which is also working fine on my side. https://textuploader.com/1dap1 Let us know about the testing result. We will try to provide further suggestions, if needed. – Deepak-MSFT Apr 24 '19 at 02:25

1 Answers1

1

I have done some changes mentioned in the comments (like changing the endless loop etc.) and also have another errors ( Automation error The object invoked has disconnected from its clients).. Previously I have declared IE as a object in this line below:

Set ObjIE = CreateObject("InternetExplorer.Application")

Soultion for all my problems:

Dim IE as SHDocVw.InternetExplorer
Set IE = New InternetExplorerMedium

Thank you all for participating in this thread and THANK YOU SO MUCH for your help!

Hlostu
  • 21
  • 2