Link to home
Start Free TrialLog in
Avatar of Prudent1
Prudent1Flag for United States of America

asked on

navigate web using vba

I am trying to navigate through a web page using vba.

I have gotten up to a certain page and got stuck.

I have to navigate two more pages and get the url links on for various items

Then  I can give this urls to excel and down load those pages into excel to manipulate it.

Also the codes work when I put break point at each       For i = 0 To IE.Document.All.Length - 1
other wise it gives me an error.
Private Sub FindInventNo_Click()
 
    Dim oForm
    Dim oElement
    Dim IE As Object, frm As Object, TheValue As String
    Dim tr
    Set IE = CreateObject("InternetExplorer.application")
        IE.Navigate ("https://www9.nysdot.gov/CSSWebView/CSS/Registration/FirmSearch.do?leftMenuContext=FirmSearchRep&action=getFirms&leftMenuContext=icmsinitfirminfo")
        IE.StatusBar = False
        IE.Toolbar = False
        IE.Visible = True
        IE.Resizable = False
        IE.AddressBar = True
' IE.Document.All("Active Reports").selectedIndex = 3
Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
  DoEvents
  Loop
   With IE.Document
    .All("fedIDNumber").Value = "0452"
    .All("forward").Item(0).Click
   End With
   
Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
  DoEvents
  Loop
 
For i = 0 To IE.Document.All.Length - 1 'lists through all elements on web page'
  If IE.Document.All(i).innerText = "Select Firm" And IE.Document.All(i).tagname = "A" Then 'if element contains text "Active Reports" and is anchor type'
    IE.Document.All(i).Click 'then click on it'
  End If
Next i
 
Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
  DoEvents
  Loop
 
   
For i = 0 To IE.Document.All.Length - 1 'lists through all elements on web page'
  If IE.Document.All(i).innerText = "Active Reports" And IE.Document.All(i).tagname = "A" Then 'if element contains text "Active Reports" and is anchor type'
    IE.Document.All(i).Click 'then click on it'
  End If
Next i
 
 
 'I am stuck after this!
 
 Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
  DoEvents
  Loop
  
For i = 0 To IE.Document.All.Length - 1 'lists through all elements on web page'
  If IE.Document.All(i).innerText = "Construction Inspection Project Inventory " And IE.Document.All(i).tagname = "A" Then 'if element contains text "Active Reports" and is anchor type'
    IE.Document.All(i).Click 'then click on it'
  End If
Next i
    
 
End Sub

Open in new window

Avatar of GPrentice00
GPrentice00

What type of error do you get when you don't have the break?  That would be fundamentally important to identifying the cause...
Avatar of Prudent1

ASKER

GP

When  there are no breaks inserted, it gives error

at       With IE.Document
error is
Run time error 70
Permission denied


at

For i = 0 To IE.Document.All.Length - 1 'lists through all elements on web page'
  If IE.Document.All(i).innertext = "Active Reports" And IE.Document.All(i).tagname = "A" Then 'if element contains text "Active Reports" and is anchor type'

Error is
Run time error 91
Object variable or With block variable not set

It varies between these two errors
ASKER CERTIFIED SOLUTION
Avatar of c0ldfyr3
c0ldfyr3
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For some reason it is still not working.
Some one else added 10 sec and that is working.

see id I
D: 23768833

thanks very much.