• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Loop through items in drop down of a field on website

Hi !

It first depends on which way you use to read the URL !
As I can't see any code …
Easy just by reading webpage code and
using webbrowser inner inspector tool.
 
Run this script. It will fetch you all the "areas of application" and "region" from two drop down menus.
Code:
Sub Dropdown_Items()
    Dim IE As New InternetExplorer, html As HTMLDocument
    Dim posts As Object, post As Object, elem As Object

    With IE
        .Visible = True
        .navigate "https://www.sptv.ch/trainersuche"
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Set html = .document
    End With
  
    Application.Wait (Now() + TimeValue("00:00:005"))
    Set posts = html.getElementsByClassName("upme-p upme-search-p upme-multiselect-p")
  
    Set post = posts(0).getElementsByTagName("select")(0).getElementsByTagName("option")
    For x = 0 To post.Length - 1
        Cells(x + 1, 1) = post(x).innerText
    Next x
  
    Set elem = posts(1).getElementsByTagName("select")(0).getElementsByTagName("option")
    For y = 0 To elem.Length - 1
        Cells(y + 1, 2) = elem(y).innerText
    Next y
  
    IE.Quit
End Sub

Reference to add to the library:
Code:
1. Microsoft Internet Controls
2. Microsoft Html Object Library
 
Or with xmlhttp request (the fastest method):

Code:
Sub WebData()
    Dim http As New XMLHTTP60, html As New HTMLDocument
    Dim posts As Object, post As Object, elem As Object

    With http
        .Open "GET", "https://www.sptv.ch/trainersuche/", False
        .send
        html.body.innerHTML = .responseText
    End With
    Set posts = html.getElementsByClassName("upme-p upme-search-p upme-multiselect-p")

    Set post = posts(0).getElementsByTagName("select")(0).getElementsByTagName("option")
    For x = 0 To post.Length - 1
        Cells(x + 1, 1) = post(x).innerText
    Next x

    Set elem = posts(1).getElementsByTagName("select")(0).getElementsByTagName("option")
    For y = 0 To elem.Length - 1
        Cells(y + 1, 2) = elem(y).innerText
    Next y
End Sub

Reference to add to the library:
Code:
1. Microsoft html Object Library
2. Microsoft xml, v6.0 or whatever version you have
 
Back
Top