sthack99
Board Regular
- Joined
- May 16, 2006
- Messages
- 237
Hi all. I am building a macro that will go to a particular county court website (depending on criteria in the worksheet), gather information about the subject case, and return the results to the worksheet. The worksheet will have the following columns (among others): State, County, Case Number, Status, Docket. The information is gathered from State, County, and Case Number, run through a function to determine which website to visit, then I ultimately want the code to search that case number and return the case status (Active, Pending, Dismissed, etc.) in the Status column, and a link to the docket in the Docket column.
The website links are on a different sheet (called "Websites").
The only way I can think to do this is to program the automation for each site individually, which I have no problem doing. However, of course, the 1st website I'm working with, I'm having issues. I'm able to get it to head to the website, enter in the case number, and hit submit, but then for some reason it won't click the case number link that appears in the table results.
Until I get past this part, I have turned off the loop in my code. Here's the code I have so far. The website I'm currently working with is Case Search. The information for the first case (found in row 2) is State = FL, County = Broward, and Case Number = CACE13021641.
Please take a look and tell me what you think I'm doing wrong.
Here's the function to determine the correct website, if you're interested:
The website links are on a different sheet (called "Websites").
The only way I can think to do this is to program the automation for each site individually, which I have no problem doing. However, of course, the 1st website I'm working with, I'm having issues. I'm able to get it to head to the website, enter in the case number, and hit submit, but then for some reason it won't click the case number link that appears in the table results.
Until I get past this part, I have turned off the loop in my code. Here's the code I have so far. The website I'm currently working with is Case Search. The information for the first case (found in row 2) is State = FL, County = Broward, and Case Number = CACE13021641.
Please take a look and tell me what you think I'm doing wrong.
Code:
Public Sub GetCaseStatus()
Dim IE As Object
Dim URL As String
Dim RowNum As Integer
Dim RowCount As Integer
Dim State As String
Dim County As String
Dim CountyList As Range
Dim CaseNum As String
Dim link As Object
Dim doc As Object
Set CountyList = Worksheets("Websites").Range("C2:E150")
Set IE = CreateObject("InternetExplorer.Application")
RowNum = 2
RowCount = ActiveSheet.UsedRange.Rows.Count
' Do While RowNum <= RowCount
State = ActiveSheet.Range("D" & RowNum).Value
County = ActiveSheet.Range("E" & RowNum).Value
CaseNum = ActiveSheet.Range("G" & RowNum).Value
URL = CourtWebsite(State, County, CountyList)
IE.navigate URL
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = 4
IE.document.GetElementById("ctl00_ContentPlaceHolder1_txtCaseNumber").Value = CaseNum
IE.document.GetElementById("ctl00_ContentPlaceHolder1_sbmPublicCase").Click
Do
DoEvents
Loop Until IE.readyState = 4
Set doc = IE.document
For Each link In doc.getElementsByTagName("table")
If link.document.Title = CaseNum Then
link.document.Links(0).Click
End If
Next link
RowNum = RowNum + 1
' Loop
End Sub
Here's the function to determine the correct website, if you're interested:
Code:
Public Function CourtWebsite(case_state As String, case_county As String, list As Range)
CourtWebsite = Application.WorksheetFunction.VLookup(case_state & "-" & case_county, list, 3, False)
End Function