[b]Function GetIEApp(WindowTitle As String) As Object[/b]
Dim objShell As Object
Dim objWindows As Object
Dim objWindow As Object
Set objShell = CreateObject("Shell.Application")
Set objWindows = objShell.Windows
For Each objWindow In objWindows
If objWindow.LocationName = WindowTitle Then
Set GetIEApp = objWindow
Exit For
End If
Next
Set objWindow = Nothing
Set objWindows = Nothing
Set objShell = Nothing
End Function
[b]Sub GetFields()[/b]
On Error GoTo GetFields_Error
Dim objIE As Object
Dim objForms As Object, objForm As Object
Dim objInputElement As Object
Dim lngRow As Long
'The following requires that a IE window is open to [URL unfurl="true"]www.monster.com[/URL]
Set objIE = GetIEApp("[i]Monster Jobs - Get work. Network. Build a better career. Today's the day.[/i]")
'Make sure an IE object was hooked
If TypeName(objIE) = "Nothing" Then
Stop
MsgBox "Could not hook Internet Explorer object", vbCritical, "GetFields() Error"
GoTo Clean_Up
End If
'Get the forms object
Set objForms = objIE.Document.Forms
'Test to see if there are forms before proceding
If objForms.Length <> 0 Then
'Write the header
lngRow = lngRow + 1
With ActiveSheet
.Cells(lngRow, 1) = "Form_Name"
.Cells(lngRow, 2) = "Form_ID"
.Cells(lngRow, 3) = "Element_Name"
.Cells(lngRow, 4) = "Element_ID"
.Cells(lngRow, 5) = "Element_nodeName"
.Cells(lngRow, 6) = "Element_Type"
.Cells(lngRow, 7) = "Element_Value"
End With
'End Header
'Cycle through all the forms in the document
For Each objForm In objForms
'Cycle through the input elements in the form
For Each objInputElement In objForm
lngRow = lngRow + 1
Stop
With ActiveSheet
.Cells(lngRow, 1) = objForm.Name
.Cells(lngRow, 2) = objForm.ID
.Cells(lngRow, 3) = objInputElement.Name
.Cells(lngRow, 4) = objInputElement.ID
.Cells(lngRow, 5) = objInputElement.nodeName
.Cells(lngRow, 6) = objInputElement.Type
.Cells(lngRow, 7) = objInputElement.Value
End With
Next objInputElement
Next objForm
End If
Clean_Up:
Set objInputElement = Nothing
Set objForm = Nothing
Set objForms = Nothing
Set objIE = Nothing
Exit Sub
GetFields_Error:
Debug.Print Err.Number, Err.Description
Resume Clean_Up
End Sub