r/visualbasic • u/EnviJusticeWarrior • Aug 21 '24
Absolute Non-Coder trying to download search results
Hi,
I am absolute non-coder, but really need to be able to download search results from an ancient government website. It seems as if I can accomplish this task with Excel by writing a bit of code. AI gave me the following code:
Sub GoToDIBBSAndClickDates()
Dim IE As Object
Dim dateCell As Object
Dim dateLink As Object
Dim dateTable As Object
Dim i As Long
' Create an instance of Internet Explorer
Set IE = CreateObject("InternetExplorer.Application")
' Navigate to the DIBBS homepage
IE.Navigate "https://www.dibbs.bsm.dla.mil/"
IE.Visible = True
' Wait for the page to load
Do While IE.Busy Or IE.ReadyState <> 4
DoEvents
Loop
' Click the "OK" button (assuming it has an ID or name attribute)
IE.Document.getElementById("butAgree").Click
' Navigate to the RFQ dates page
IE.Navigate "https://www.dibbs.bsm.dla.mil/RFQ/RfqDates.aspx?category=close"
' Wait for the page to load
Do While IE.Busy Or IE.ReadyState <> 4
DoEvents
Loop
' Assuming the table has an ID "ctl00_cph1_dtlDateList"
Set dateTable = IE.Document.getElementById("ctl00_cph1_dtlDateList")
If Not dateTable Is Nothing Then
' Iterate through each row (skip the header row)
For i = 1 To dateTable.Rows.Length - 1
Set dateCell = dateTable.Rows(i).Cells(0) ' Assuming the date cell is in the first column
Set dateLink = dateCell.getElementsByTagName("a")(0)
If Not dateLink Is Nothing Then
dateLink.Click
' Wait for the page to load (adjust as needed)
Do While IE.Busy Or IE.ReadyState <> 4
DoEvents
Loop
End If
Next i
Else
MsgBox "Date table not found!"
End If
' Clean up
IE.Quit
Set IE = Nothing
End Sub
I am receiving a runtime 424 error message that says Object Required in the line
Set dateTable = IE.Document.getElementById("ctl00_cph1_dtlDateList")
The website is Return By Dates for RFQs (dla.mil), but to access that page, you have to click OK to access the website, but you do not have to login.
Will someone please take a look at the code and website and fix for me? Thanks!
View all comments
Show parent comment
2
u/jd31068 Aug 23 '24 edited Aug 23 '24
I see, you will want to mimic the clicking of the OK button. In the td - do a FindByTag("a") and use the href attribute of it to open that URL. You might consider putting them in an array. That way you can get all of them from that table and then go to each URL separately.
Do they point to PDFs or HTML? This sounds like there may be some complex HTML data structures you want to import. How would you want this structured in Excel?
EDIT: I did quick view of 8/6/24 - and see that that leads to another page that has another link that needs clicking and that is a PDF but before you can get the PDF, you want to download this I assume and save it to a specified location or read it into another file? you have to click and okay button again.
This is all doable, but it is much more work.