R
ryguy7272
I have a reference set to ‘Microsoft HTML Object Library’ and I have a
reference set to ‘Microsoft internet Controls’.
On the web page that I’m working with, I hit F12 in IE, and see the
following:
FirstName:
<input name="FName" onkeypress="clear_ID();" type="text"
maxLength="25" AUTOCOMPLETE="OFF" value="Sammy"/>
LastName:
<input name="LName" onkeypress="clear_ID();" type="text"
maxLength="25" AUTOCOMPLETE="OFF" value="Surefit"/>
I want to input the FirstName and the LastName, and then click the
‘Search’ button
Button:
<input id="btn_quicksearch_label"
onclick="JavaScript:SubmitForm_Name();" type="button" value="Search"/>
Then, on the next page (after clicking the Search button), I want to
copy/paste something called SOEID into Row = RowCount and Column = AA.
Below is the code that I’m testing:
Sub CopyFromSite()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
Dim LastRow As Long
With Worksheets("List of FAs")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
On Error GoTo Err_Clear
sURL = "http://gdir.nam.nsroot.net/globaldir/"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
'oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.document
'With Sheets("List of FAs")
RowCount = 2
Dim FirstName_Label As String
Dim LastName_Label As String
'For Each . . .
FirstName_Label = .Cells(RowCount, "A") 'FirstName.Text
LastName_Label = .Cells(RowCount, "B") 'LastName.Text
HTMLDoc.all.FirstName_Label.Value = FirstName_Label
HTMLDoc.all.LastName_Label.Value = LastName_Label
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit
For
Next
For Each oHTML_Element In HTMLDoc.getElementsByTagName("SOEID")
.Cells(RowCount, "AA") = SOEID.Text
Next
RowCount = RowCount + 1
'Next . . .
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End With
End Sub
From what I can tell, this looks good, but Excel is telling me, ‘no
way, buddy’. The code fails on this line:
HTMLDoc.all.FirstName_Label.Value = FirstName_Label
Error mssg is ‘Object doesn’t support this property or method’
I know ‘FirstName_Label’ has the right value associated with it. For
some reason, that value is NOT being passed to
‘HTMLDoc.all.FirstName_Label.Value’
I’m not sure if I actually need the For…Next loop so that stuff is
commented out for now.
Can someone please help me out here?
Thanks!!
reference set to ‘Microsoft internet Controls’.
On the web page that I’m working with, I hit F12 in IE, and see the
following:
FirstName:
<input name="FName" onkeypress="clear_ID();" type="text"
maxLength="25" AUTOCOMPLETE="OFF" value="Sammy"/>
LastName:
<input name="LName" onkeypress="clear_ID();" type="text"
maxLength="25" AUTOCOMPLETE="OFF" value="Surefit"/>
I want to input the FirstName and the LastName, and then click the
‘Search’ button
Button:
<input id="btn_quicksearch_label"
onclick="JavaScript:SubmitForm_Name();" type="button" value="Search"/>
Then, on the next page (after clicking the Search button), I want to
copy/paste something called SOEID into Row = RowCount and Column = AA.
Below is the code that I’m testing:
Sub CopyFromSite()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
Dim LastRow As Long
With Worksheets("List of FAs")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
On Error GoTo Err_Clear
sURL = "http://gdir.nam.nsroot.net/globaldir/"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
'oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.document
'With Sheets("List of FAs")
RowCount = 2
Dim FirstName_Label As String
Dim LastName_Label As String
'For Each . . .
FirstName_Label = .Cells(RowCount, "A") 'FirstName.Text
LastName_Label = .Cells(RowCount, "B") 'LastName.Text
HTMLDoc.all.FirstName_Label.Value = FirstName_Label
HTMLDoc.all.LastName_Label.Value = LastName_Label
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit
For
Next
For Each oHTML_Element In HTMLDoc.getElementsByTagName("SOEID")
.Cells(RowCount, "AA") = SOEID.Text
Next
RowCount = RowCount + 1
'Next . . .
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End With
End Sub
From what I can tell, this looks good, but Excel is telling me, ‘no
way, buddy’. The code fails on this line:
HTMLDoc.all.FirstName_Label.Value = FirstName_Label
Error mssg is ‘Object doesn’t support this property or method’
I know ‘FirstName_Label’ has the right value associated with it. For
some reason, that value is NOT being passed to
‘HTMLDoc.all.FirstName_Label.Value’
I’m not sure if I actually need the For…Next loop so that stuff is
commented out for now.
Can someone please help me out here?
Thanks!!