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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making VBA select multiple criteria in a listbox on a webpage 1

Status
Not open for further replies.

clouddog9

Technical User
Jul 31, 2009
55
US
Hi, first post:

I am trying to make an application select multiple parameters from a listbox on a webpage.

The HTML for the listbox is as follows:
Code:
<script>
genSelectValueHTML("_P1798642992", 'formWarpRequest', "GL_Period_Name", 'XML', 'prompt', 'listBox', "GL_Period_Name", RANGE_NO_VALUE, false, false, false, false, false, true, false, "",null, 160);listBox_P1798642992.addOptions([["ADJ-Q1-2011","ADJ-Q1-2011"],["ADJ-Q1-2012","ADJ-Q1-2012"],["ADJ-Q1-2013","ADJ-Q1-2013"],["ADJ-Q1-2014","ADJ-Q1-2014"],["ADJ-Q1-FY05","ADJ-Q1-FY05"],["ADJ-Q1-FY06","ADJ-Q1-FY06"],["ADJ-Q1-FY07","ADJ-Q1-FY07"],["ADJ-Q1-FY08","ADJ-Q1-FY08"],["ADJ-Q1-FY09","ADJ-Q1-FY09"],["ADJ-Q1-FY10","ADJ-Q1-FY10"],["ADJ-Q2-2011","ADJ-Q2-2011"],["ADJ-Q2-2012","ADJ-Q2-2012],null]);</script></div></td></tr>

Anybody got any suggestions?
 
looks like it's using javascript to create the listbox. you'll need to examine that code and see what or ID it gives the listbox for the final html render. Then you can use the document.getElementByID method of an IE object.
 
Do you where this should be in comparison to the code that I placed above?
 
Seems like the ID is listBox_P1798642992

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What would be the VBA code to choose something from this listbox?
 
I think you can just use the value property of the listbox once you have its ID and set it equal to one of the options:

Code:
objIE.Document.All("listBox_P1798642992").Value = "ADJ-Q1-2011"
 
I get a run time error 91 with this code. Does it matter that the listbox is in another frame?
 
Did you create your IE object?

Code:
Dim objIE as Object

Set objIE = CreateObject("Application.InternetExplorer")

Maybe you should post what code you have.
 
Code:
Sub CognosInterface()

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
    .navigate '1st website
    .Visible = True

    Do Until .readyState = 4 And .busy = False: DoEvents: Loop
    Do Until .document.readyState = "complete": DoEvents: Loop

    .document.all("USER").Value = "default" 'Put your username here
    .document.all("PASSWORD").Value = "default" 'put your password here
    .document.all("go").Click

    .navigate '2nd website

    Do Until .readyState = 4 And .busy = False: DoEvents: Loop
    Do Until .document.readyState = "complete": DoEvents: Loop
    
lblLinkFind:
Dim LinkFound As Boolean
Dim linkCollection
Set linkCollection = .document.getElementsByTagName("A")
For Each link In linkCollection
If link.innerText = "Report - details" Then
LinkFound = True
link.Click
Exit For
End If

Next


If Not LinkFound Then
GoTo lblLinkFind:
End If

    Do Until .readyState = 4 And .busy = False: DoEvents: Loop
    Do Until .document.readyState = "complete": DoEvents: Loop
    
.document.all("_P1610431606").Value = 'Selections Here
    
End With




End Sub

I had to take out somethings since they pretained to my company. I'd prefer not to get fired for putting something that could be considered sensetive.
 
So I'm guessing the error is happening here:
Code:
.document.all("_P1610431606").Value = 'Selections Here

How did you verify the ID of that element?

PHV gave a good guess on the ID but I don't think you can really be sure of what it is unless you see their actual javascript and what that genSelectValueHTML function does. The javascript will be somewhere in the HTML inside of script tags (usually towards the top, just do a search for that function name. Should look something like
Code:
function genSelectValueHTML(...) {
   xxx
}

If you don't find it embedded on the page, it might be in a separate script file. In which case you need to look on the page for tags that look like:

Code:
<script src="...">

The src attribute will tell you the path/name of the script file that is referenced. There could be more than 1 as well so you'll need to check them all. The way you can view them is by following the path listed in the src attribute from the path of the page your looking at. For example if the src attribute is "../resources/myscript.js", and your html page is " then you can view the file by going to " If you view the source in firefox, it looks like it puts a link for referenced files in the html that you can click as well and view the source of those files.

Once you find the actual javascript function that's creating the dropdown, then you need to analyze it and see where it's getting it's id attribute from and use that in the document.all() property.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top