I am stuck...obviously. I was tasked with gathering some data on a long list of companies for my supervisor (I'm a grad assistant) from a messy website (i.e. no specific URLs for each report). I wrote a "simple" program to open internet explorer, navigate through a disclaimer page, change the value of a drop-down, wait for the page to automatically update, then click a link that launches a report. My plan was to simply copy the page that is launched and paste it into a worksheet and find the relevant data I need after that. The website turned out to be a nightmare but I managed to launch the report I had specified. However, the report is launched in a new tab and I have no idea how to navigate there.
From what I have read I believe I need to re-write the code using a shell extension but I have no experience with this and was hoping someone could help. I could probably figure it out eventually by teaching myself some of this new programming but it seems like a large task to complete before Monday (spreadsheet is due). Also, this will be a one-time assignment so I'm looking for something as simple as possible and all the other examples seem too complicated. My current code is below. I have hacked it to pieces trying to figure this out so my apologies for messy code. The shell is my main issue but if someone also has a suggestion gathering the information from the final report more efficiently, I would love suggestions. Thanks in advance.
FYI...
Windows 7, Excel 2010, Internet Explorer 9
From what I have read I believe I need to re-write the code using a shell extension but I have no experience with this and was hoping someone could help. I could probably figure it out eventually by teaching myself some of this new programming but it seems like a large task to complete before Monday (spreadsheet is due). Also, this will be a one-time assignment so I'm looking for something as simple as possible and all the other examples seem too complicated. My current code is below. I have hacked it to pieces trying to figure this out so my apologies for messy code. The shell is my main issue but if someone also has a suggestion gathering the information from the final report more efficiently, I would love suggestions. Thanks in advance.
FYI...
Windows 7, Excel 2010, Internet Explorer 9
Code:
Sub gather()
'
Dim ie As Object
Dim ElementCol As Object
Dim btnInput As Object
Dim linkElement As Object
Dim Link As Object
Dim wait As Long
Dim i As Integer
Dim compCode As String
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.navigate "https://i-site.naic.org/grid/gridDisc.jsp"
While ie.Busy
DoEvents
Wend
Set ElementCol = ie.document.getElementsByTagName("input")
'loop through all 'input' elements and find the one with the value "I Agree"
For Each btnInput In ElementCol
If btnInput.Value = "I Agree" Then
btnInput.Click
Exit For
End If
Next btnInput
While ie.Busy
DoEvents
Wend
ie.document.getElementById("Company").Value = "60994"
While ie.Busy
DoEvents
Wend
ie.document.forms("criteria").Item("COMPANY").FireEvent ("onchange")
Application.wait Time + TimeSerial(0, 0, 10)
While ie.Busy
DoEvents
Wend
' click a text link on the page after that
Set linkElement = ie.document.getElementsByTagName("a")
For Each Link In linkElement
If Link.href = "javascript:fnSubmit()" Then
Link.Click
Exit For
End If
Next Link
While ie.Busy
DoEvents
Wend
ie.ExecWB 17, 0 'SelectAll
ie.ExecWB 12, 2 'Copy selection
Sheets("Output").Select
Cells.ClearContents
Range("A1").Select
ActiveSheet.Paste
End Sub