Select all in IE options element through VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tabasco
    New Member
    • Oct 2012
    • 25

    #1

    Select all in IE options element through VBA

    Hello, i am trying to choose all the options in selection box in IE by using vba, i've no trouble choosing one value however when i'm trying to choose another value the first value becomes unmarkt, as if you would do it manually with a mouse. If you want to select several values with a mouse you have to hold down shift so.

    The element has 290 option values so i would rather not want to write code to select every value but i suspect I can write a loop who either selects every value one by one, or, selects the first value and the last by holding down "shift".

    Does anyone have an idea?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Assuming that multi select is enabled on the list, you have to loop through the options and set the selected property of each.

    Comment

    • Tabasco
      New Member
      • Oct 2012
      • 25

      #3
      yes it is a multiple select. I get the loop to work however it seems im missing something because the options wont stay selected as they loop through the opions.

      Code:
      Dim m as double
      m = 0
      
      X = ieApp.Document.getElementbyId("Element_ID").Length - 1
      
      Do Until m = X
      
      ieApp.Document.getElementbyId("Element_ID").Value = ieApp.Document.getElementbyId("Element_ID").Item([m]).Value
      
      
      m = m + 1
      Loop
      it seems im missing something in the loop to keep the values selected because now the loop says, "Select that value" and then "Select that value"

      I need something like "Select that value and select that value" etc.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        options in selection box
        If you mean as in a group box and these are actually "option controls" or "option buttons" then these will work like radio buttons - this is by design. You can not use them as a multi select element
        You have to unlink them from the selection box by changing the associations...
        Closer Look: Using Multiple Groups of Radio Buttons
        Visual Studio 2008
        (see also the level before this link - you should consider check boxes instead)

        I realize that this is a VB and not VBA reference; however, this still applies as it is common to both languages just the syntax varies.

        Comment

        • Tabasco
          New Member
          • Oct 2012
          • 25

          #5
          I'm not trying to build a form i am trying to preset a number of selections on a web page on a selection box who look like this in scource. Multiple values are possible but i dont know how to select more then one at a time!


          Code:
              <select size="5" name="ctl00$LeftMainRightContentPlaceHolder$MainContentPlaceHolderRemove$MainContentPlaceHolder$VariableSelector1$VariableSelector1$VariableSelectorValueSelectRepeater$ctl02$VariableValueSelect$VariableValueSelect$ValuesListBox" multiple="multiple" id="ctl00_LeftMainRightContentPlaceHolder_MainContentPlaceHolderRemove_MainContentPlaceHolder_VariableSelector1_VariableSelector1_VariableSelectorValueSelectRepeater_ctl02_VariableValueSelect_VariableValueSelect_ValuesListBox" class="variableselector_valuesselect_valueslistbox" onchange="UpdateNumberSelected('ctl00_LeftMainRightContentPlaceHolder_MainContentPlaceHolderRemove_MainContentPlaceHolder_VariableSelector1_VariableSelector1_VariableSelectorValueSelectRepeater_ctl02_VariableValueSelect_VariableValueSelect_ValuesListBox', 'ctl00_LeftMainRightContentPlaceHolder_MainContentPlaceHolderRemove_MainContentPlaceHolder_VariableSelector1_VariableSelector1_VariableSelectorValueSelectRepeater_ctl02_VariableValueSelect_VariableValueSelect_NumberValuesSelected', 'Stub','Cells')">
          						<option value="0114">0114 Upplands Väsby</option>
          						<option value="0115">0115 Vallentuna</option>
          						<option value="0117">0117 Österåker</option>
          So how do i select for example these three values?
          Last edited by Tabasco; Jan 26 '13, 07:14 PM. Reason: clarification

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            You are going to have tell us exactly which selection box control you're trying to use with VBA. The ones that I've normally seen in use act like radio buttons.

            However, with that said, the only control I've seen that will allow this within the web-page is this: Selection Box Web component General tab (iwcl:WSelectio nBox)

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              The problem is that you're looping and setting the value of the select element. I said you need to loop through and set the selected property of the option element.

              Comment

              Working...