Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE - Selecting multiple Selections from Select element

Status
Not open for further replies.

MacroMan2

Programmer
May 6, 2011
1
GB
Hi everyone,
I have some code below, that is used to select an option from a drop down list and submit a form, which works fine. My work has just changed the drop down box to a multi select box. How can I change the following lines to select multiple items in one go?
Code:
For i = 1 To 200
myIE.Document.forms(mySearchForm).elements(mySearchInput).Value = Sheets("Currencies").Cells(i, 3).Value
Next i
I thought the above code should work, but each time it loops, it selects a new value instead of adding to the current selection.

The full code in current use is this:

Code:
Sub AddCur()
Sheets("Auto Currencies").Unprotect
Sheets("Auto Currencies").Cells(13, 13).Value = "0"
Const myPageTitle As String = "Manage Currency Codes"
Const mySearchForm As String = "manageCurrency"
Const mySearchInput As String = "currencyCode"
Const myStatusInput As String = "currencyStatus"
Const myStatus As String = "002"
Const myButton As String = "Add"
Dim i As Integer
Dim AIndex As Double
Dim AddAm As Double

Dim myIE As SHDocVw.InternetExplorer

'check if page is already open
Set myIE = GetOpenIEByTitle(myPageTitle, False)

AddAm = 100 / Application.CountA(Sheets("Currencies").Range("C:C"))

For i = 1 To 200
If (Sheets("Currencies").Cells(i, 3).Value = "") Then
Exit For
End If
With myIE.Document.forms(mySearchForm)
'enter search term in text field
.elements(mySearchInput).Value = Sheets("Currencies").Cells(i, 3).Value
'press button "Go"
.elements(myStatusInput).Value = myStatus
.elements(myButton).Click
End With
Dim vReadyState 'check if page is fully loaded. 4 = loaded
vReadyState = 0
Application.Wait DateAdd("s", 2, Now)
Do Until vReadyState = 4
DoEvents
vReadyState = myIE.ReadyState
Loop
AIndex = AIndex + AddAm
Sheets("Auto Currencies").Cells(13, 13).Value = AIndex
Next i
Sheets("Auto Currencies").Cells(13, 13).Value = ""
Sheets("Auto Currencies").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
MsgBox ("Add all currencies complete.")
End Sub
Many thanks for your help

David
 
Never really messed around with multiselect combo boxes. But something you can do is manually make a multiple selection inside the combo box, step into your code until you can add a watch for your combo box (dimensionalize the variable for the element, assign the element to the variable, watch the variable)

Then, observe the .Value property of the element variable.

I hope that made sense.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top