?
Solved

navigate web using vba

Posted on 2008-09-29
4
Medium Priority
?
2,033 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:Prudent1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:GPrentice00
ID: 22601387
What type of error do you get when you don't have the break?  That would be fundamentally important to identifying the cause...
0
 

Author Comment

by:Prudent1
ID: 22601552
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
0
 
LVL 10

Accepted Solution

by:
c0ldfyr3 earned 1000 total points
ID: 22601679
Try this,...

For i = 0 To IE.Document.All.Length - 1 'lists through all elements on web page'
  If Not IE.Document.All(i) Is Nothing Then 'If we have no object then no need to check it.'
    If IE.Document.All(i).tagname = "A" Then 'innerText might not be available to all items so only check anchors.'
      If IE.Document.All(i).innerText = "Active Reports" Then 'if element contains text "Active Reports" and is anchor type'
        IE.Document.All(i).Click 'then click on it'
      End If
    End If
  End If
Next i

Open in new window

0
 

Author Comment

by:Prudent1
ID: 22605446
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question