VBA

Moderators: PavlinII
Number of threads: 1673
Number of posts: 3078

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
IE - Selecting multiple Selections from Select element Posted by MacroMan2 on 6 May 2011 at 7:03 AM
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?
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:

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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.