Manipulating Combobox in Internet Explorer

  • Hi all,

    I've been having trouble trying to manipulate a dropdown/combobox in internet explorer. The combo box looks as below


    I can see the HTML for the element reads as below

    I'm attempting to select EMAIL from the dropdown box. I can change the value of FMT_TYP_CDtxt to EMAIL, however when I submit this it reverts back to default. I have also noticed that I'm able to change the value to anything, even if it is not in the dropdown list. This makes me think that referencing FMT_TYP_CDtxt is incorrect.

    Please see my code so far

    I'm literally at the end of my tether and I would appreciate any assistance massively. This is the last part of the process and it's killing me.


  • Re: Manipulating Combobox in Internet Explorer

    It isn't a conventional dropdown (HTML select element). Try triggering the click event:

    Dim table As HTMLTable  'needs reference to HTML Object Library
        Set table = ie.document.getElementById("FMT_TYP_CDTable")
        table.Rows(3).Cells(0).Click  'or .FireEvent "onclick"
  • Re: Manipulating Combobox in Internet Explorer

    Hi John,

    Thanks for your response. I seem to be getting a type mismatch error. Any ideas?


    Apologies, I hadn't changed the DIM statement. However, now I'm getting an "Object Required" error

  • Re: Manipulating Combobox in Internet Explorer

    Quote from John_w;755314

    You need to set a reference to MS HTML Object Library in the VBA editor Tools -> References menu.

    I believe this is already the case, otherwise the HTMLTable dimension would flag an error? The error happens on the ie.document.getelementbyid() line. I have Microsoft HTML Object Library selected. Is there anything else I should have activated?

  • Re: Manipulating Combobox in Internet Explorer

    Yes, without the reference the code wouldn't compile and would cause a run-time error at the Dim line.

    Assuming you've put my code in a sensible place, i.e. after the page has loaded, an "Object required" error on

    Set table = ie.document.getElementById("FMT_TYP_CDTable")

    means the element with that id doesn't exist, or a timing issue means it is not available at that point in time. The element should exist according to your HTML:

    <table class="combo-list-width" id="FMT_TYP_CDTable" cellpadding="0" cellspacing="0">

    To test whether it is a timing issue, set a breakpoint (press the F9 key on that line), run the code to the breakpoint, wait a second or so and then continue.

  • Re: Manipulating Combobox in Internet Explorer

    Tend to run line by line anyway. I can only seem to find the table reference when I inspect the element. The raw HTML data for the page doesn't seem to make any reference to "FMT_TYP_CDTable". Would this have any impact? It seems to adjust the values in the other text boxes without any issue.

    Is it possible that the element only comes into existence once the dropdown box has been activated?

  • Re: Manipulating Combobox in Internet Explorer

    If the element with id "FMT_TYP_CDTable" doesn't exist then you would get the error, so yes it is possible that the element only exists when the dropdown is activated.

    You could call this function to log the HTML to help with debugging:

    Private Sub Log_HTML(HTML As String)
        Static num As Integer
        num = num + 1
        Open "C:\folder\path\HTML" & num & Format(Now, " hh mm ss") & ".txt" For Output As #1   'CHANGE FOLDER PATH
        Print #1, HTML
        Close #1
    End Sub

    and call it at appropriate points in the code and with an appropriate element, like this:

    Log_HTML ie.Document.body.outerHTML
        Log_HTML table.outerHTML

    I sometimes call it inside a timed loop and record the HTML during manual interaction with the browser:

    Dim timeout As Date
        timeout = DateAdd("s", 5, Now)
            Log_HTML ie.Document.body.outerHTML
            Application.Wait DateAdd("s", 1, Now)  'or Windows API Sleep for < 1 second interval
        Loop Until Now >= timeout

    Then visually compare the HTML*.txt files created or use to find differences in them.

    That's really all the help I can give.

  • Re: Manipulating Combobox in Internet Explorer

    It's more help than I ever could have expected.

    Thanks John, I will try this and revert back (hopefully with a success story). Perhaps I can activate the dropdown and then manipulate the table.

  • Re: Manipulating Combobox in Internet Explorer

    Hi Jon,

    I finally managed to resolve this

       Set table = ie.document.getElementById("FMT_TYP_CDTable")

    My hunch was correct, the element only comes into existence when the dropdown button is activated. I had to go through all the buttons to figure out which one was correct. Everything is now working as it should, thanks for your help!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!