vba interacting with HTMLselectelement with onchange property

I am trying to automate entries to a web page and I am getting stuck on a select element that contains an onchange property.  When a selection is made by clicking on one of the option elements, new information is added to the webpage.  When I try to automate this selection using vba, the onchange property does not seem to be activated.

Here is the source code for the HTMLselectelement I am trying to interact with.
<select id="rcat" name="rcat"
                 onchange="rr_changeHandler(this);">
          <option value="oef">Element Forces
          <option value="gpf">Grid Point Forces
          <option value="balance">Grid Point Force Balance
          <option value="oelop">Element-oriented Forces
          <option value="disp">Displacement Vectors
          <option value="maxmin">Envelope Loads
          <option value="stress">Envelope Stresses
          <option value="maxd">Envelope Displacements
          <option value="bdf">Bulk Data
          <option value="compare">Comparison (Ratios)
       </select></td>

I can select any option here, the only problem i have is triggering the onchange.
mbbarclayAsked:
Who is Participating?
 
Computer101Connect With a Mentor Commented:
PAQed with points refunded (125)

Computer101
EE Admin
0
 
EDDYKTCommented:
this works for me

<html>
<head>
 <script language="JavaScript">
   function rr_changeHandler()
   {
    alert(rcat.options(rcat.selectedIndex).text);
 
   }

 </script>

</head>
<body>
<select id="rcat" name="rcat"
                 onchange="rr_changeHandler()">
          <option value="oef">Element Forces
          <option value="gpf">Grid Point Forces
          <option value="balance">Grid Point Force Balance
          <option value="oelop">Element-oriented Forces
          <option value="disp">Displacement Vectors
          <option value="maxmin">Envelope Loads
          <option value="stress">Envelope Stresses
          <option value="maxd">Envelope Displacements
          <option value="bdf">Bulk Data
          <option value="compare">Comparison (Ratios)
       </select>
</body>
</html>
0
 
mbbarclayAuthor Commented:
Thanks for the response, but I am trying to automate the selection from this webpage using VBA.  I have no control over how the HTML is written for the webpage.  

This is what i have so far:

  Dim IE As SHDocVw.InternetExplorer
  Dim hCol As MSHTML.IHTMLElementCollection
  Dim hSel As MSHTML.HTMLSelectElement

Set hCol = IE.document.getElementsByTagName("SELECT")

For Each hSel In hCol
  If hSel.Name = "rcat" Then
  hSel.selectedIndex = 6
   Exit For
  End If
  Next hSel

This will select the option element that I need, but I cannot figure out how to interact with the onchange call.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
EDDYKTCommented:
you may want to change

Dim hSel As MSHTML.HTMLSelectElement

to declare on global as

Private WithEvents hSel As MSHTML.HTMLSelectElement


Private Sub hSel_onchange()

End Sub
0
 
EDDYKTCommented:
It is not been tested

Private WithEvents hSel1 As MSHTML.HTMLSelectElement

Private Sub hSel1_onchange()

End Sub

Dim IE As SHDocVw.InternetExplorer
  Dim hCol As MSHTML.IHTMLElementCollection
  Dim hSel As MSHTML.HTMLSelectElement

Set hCol = IE.document.getElementsByTagName("SELECT")

For Each hSel In hCol
  If hSel.Name = "rcat" Then
  hSel.selectedIndex = 6
set hSel1 = hSel
   Exit For
  End If
  Next hSel
0
 
mbbarclayAuthor Commented:
i figure it out.  I had to add a fireevent to the selectelement

Dim IE As SHDocVw.InternetExplorer
  Dim hCol As MSHTML.IHTMLElementCollection
  Dim hSel As MSHTML.HTMLSelectElement

Set hCol = IE.document.getElementsByTagName("SELECT")

For Each hSel In hCol
  If hSel.Name = "rcat" Then
  hSel.selectedIndex = 6
  hSel.FireEvent "onchange", hSel
   Exit For
  End If
  Next hSel
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.