Retain focus of IE using DocumentComplete

G

George J

I have a macro that looks at a number of URL's and extracts certain data from
it to various worksheets.

I can get the class module to use WithEvents IE As InternetExplorer, then
navigate to the desired webpage but if i try to change from one worksheet to
another within the class module, i get an error. (I assumed this was due to
withevent).

When i tried running that code in a standard module, after the
IE_Documentcomplete event had fired twice, when it got to a line Set
oResultPage = IE.Document then it no longer knew what IE refferred to - so
i'm basically trying to get a webpage (created using Set IE = New
InternetExplorer from the class module) to be recognised in the main module
for a macro to read the HTML data. The extraction code for that works fine,
but how do i keep the "focus"? I altered the code as the readystate was too
unreliable.

This is what i have in the class module

Option Explicit

Private WithEvents IE As InternetExplorer

Private Sub Class_Initialize()
On Error Resume Next
IE.Visible = True
If Err.Number <> 0 Then
Set IE = New InternetExplorer
IE.Visible = False
End If
End Sub

Public Sub Navigate(ByVal URL As String)
IE.Navigate URL
End Sub

Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim xcount As Integer
If TypeName(pDisp) <> Empty Then
gj = gj + 1
End If
If gj = 2 Then
InUse = False
End If
End Sub

So basically, from the original macro that navigated to the URL using the
class navigate, I am trying to get

For Each r In Range("A1:C60")
Do
DoEvents
Application.Wait Now() + (TimeValue("00:00:01"))
Loop Until InUse = False

If gj = 2 Then
gj = Empty
Call ExtractData
End If

when gj=2 (the DocumentComplete event has fired twice), then i want the
ExtractData macro to be able to see the webpage that the class module code
just created.

I've probably made a total mess of explaining that, but i'm going braindead
right now.
Hope someone can help with this.
George
 
G

George J

Yup - jsut me being silly again.

Set myIE = IE

in the class module and have it set as a public variable in the main macro.

doh!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top