IE Automation using Excel VBA - Unable to identify controls on web page

cmjoshi

New Member
Joined
May 9, 2016
Messages
5
Dear all,

I am trying to do IE Automation through Excel VBA code.
I have a web page which has Top, Middle and Results forms. I need to input values in the Middle form(Not sure whether it is FORM or FRAME or DOCUMENT) but unable to get any controls from this and get it as 0. Ie.Document.forms.Length gives 0. Tried the below code as well but does not work.
Ie.Document.forms("SearchForm").elements("PolicyNumber").Value = "Josh"
Looks like this form is on a frame but don't see frame reference inthe HTML code. HTML code is as below:

Top Frame: It has the Header and Menu

<HTML>
<HEAD>
<TITLE>Header Form</TITLE>
****** http-equiv=Content-Type content="text/html">
<LINK rel=STYLESHEET href="css/style.css" type="text/css">
******** type="text/javascript" language="javascript" src="/cciv/css/AigagAjax.js">*********>
******** language="JavaScript" type="text/javascript" src="/cciv/css/Contact.js">*********>
******** language="JavaScript">

Middle Frame: This is place where I need to input value in PolicyNumber and click on Submit.

<body bgcolor="white">
<form method=POST name="SearchForm" action="PolicySearch" target="resultframe" >
<input type=hidden name="NewSearch" value="True" ></input>
<table class=box2 cellpadding="1" cellspacing="0" border="0" width="760" align="top" halign="left">
<tr>
<td class="name" align="left">Policy# :<input type=text name="PolicyNumber" maxlength="10" value="" size="10"></input></td>
<td class="name" align="left">
<input class="name" type=radio name="SearchParty" value="Insured" checked></input>Insured
<input class="name" type=radio name="SearchParty" value="Owner" ></input>Owner
<input class="name" type=radio name="SearchParty" value="Payor" ></input>Payor</td>
<td class="name" align="left">SSN: <input type=text name="SSN" maxlength="9" value="" size="9"></input></td>
<td class="name" align="left"><INPUT class="SubmitButton" name="SearchSubmit" width=9 value="Search" type="submit" *******="if (parent.resultframe.displayWaitMessage) {return parent.resultframe.displayWaitMessage();} "></INPUT></td>
</tr>
<tr>
<td nowrap class="name" align="left" >Agent# :<input type=text name="AgentNumber" maxlength="10" value="" size="10"></input></td>
<td nowrap class="name" align="left">Name (Last,First): <input type=text name="PartyName" maxlength="20" value="" size="15" ></input></td>
<td nowrap class="name" align="left">DOB: <input type=text name="DOB" maxlength="10" onFocus="if(value == 'mm-dd-yyyy') {value = ''}" onBlur="isValidDate()" value="mm-dd-yyyy" size="10"></input></td>
<td nowrap class="name" align="left"><INPUT class="SubmitButton" width=9 value="Clear  " type=reset></INPUT></td>
</tr>
</table>
</form>
</body>
</html>

Please help since I am newbie in IE Automation through Excel and also newly register in this Forum. Appreciate your immediate help and support.

Thanks,
Josh
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
For f = 0 To Ie.Document.forms.Length - 1
With Ie.Document.forms(f)
MsgBox "IE.document.forms(" & f & ")"
MsgBox " .Name=" & .Name & " .ID=" & .ID & " .action=" & .Action & " .method=" & .Method
MsgBox " .elements.Length=" & .elements.Length
End With
Next

The above code is returning ZERO.

Please advise...
 
Upvote 0
Middle Frame: This is place where I need to input value in PolicyNumber and click on Submit.

HTML:
< input name="PolicyNumber" maxlength="10" value="" size="10" type="text">

Try:
Code:
IE.document.getElementsByName("PolicyNumber")(0).value = "123456"
If that part of the page is within a HTML frame then you'll need to reference the HTMLDocument within the frame instead of IE.document. There should be code showing how to do that on this forum if you search.

And this HTML for the Search button suggests it is inside a frame:
HTML:
< input class="SubmitButton" name="SearchSubmit" value="Search" *******="if (parent.resultframe.displayWaitMessage) {return parent.resultframe.displayWaitMessage();} " type="submit" width="9">
To click:
Code:
Dim theFrameDocument
'Get a reference to the frame HTML document here
theFrameDocument.getElementsByName("SearchSubmit")(0).Click
 
Upvote 0

Forum statistics

Threads
1,225,046
Messages
6,182,553
Members
453,125
Latest member
SandwichTaker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top