permission denied error when automating explorer
Yes, I understand that. I've tried waiting several different ways, and
it doesn't seem to matter. here's the code:
Sub get_data_from_site()
Dim ie As SHDocVw.InternetExplorer
Dim catone As Object
Dim cattwo As Object
Dim catthree As Object
Dim trims As New Collection
nrw = 1
Set ie = New SHDocVw.InternetExplorer
'goto main site for new cars
ie.Navigate "http://www.mysite.com"
While ie.readyState < READYSTATE_COMPLETE
DoEvents
Wend
Set catone= ie.document
'If I pause here, everything works fine. If I let it run, I get
permission denied, with the If line highlighted. Waiting doesn't seem
to help.
For Each lma In catone.Links
If InStr(1, lma, "condition1") Then
ie.Navigate lma
While ie.readyState < READYSTATE_COMPLETE
DoEvents
Wend
Set cattwo= ie.document
For Each lmo In cattwo.Links
If InStr(1, lmo, "condition2") Then
ie.Navigate lmo
While ie.readyState < READYSTATE_COMPLETE
DoEvents
Wend
Set catthree= ie.document
For Each lt In catthree.Links
If InStr(1, lt, "condition3") Then
On Error Resume Next
la = Array(lt, lt.sourceIndex)
trims.Add la, lt
On Error GoTo 0
End If
Next lt
Sheets("test").Activate
For x = 1 To trims.Count
'Cells(nrw, 1) = cat1
'Cells(nrw, 2) = cat2
c = 3
For y = trims(x)(1) To trims(x + 1)(1)
Cells(nrw, c) =
trimsdoc.all.item(y).innerText
c = c + 1
Next y
nrw = nrw + 1
Next x
End If
Next lmo
End If
Next lma
ie.Quit
Set ie = Nothing
End Sub
|