VB 6.0 webbrowser control to automate html dropdown selection

Posted on 2005-05-09
Last Modified: 2013-12-25
I had placed a webbrowser control in my form

Private Sub Form_Load()
    WebBrowser1.Navigate2 ""

    Do While WebBrowser1.Busy = True

    WebBrowser1.Document.Forms(0).Username.Value = "debehs"
End Sub

While there is a combo box with the name "cmbArea", and I need to give the answer as "Area A". I tried to code it this way but no luck.

WebBrowser1.Document.Forms(0).cmbArea.Value = "Area A"

Please Advice. Thanks in advance !!!


Web coding


<select name="cmbArea">
<option value="" selected>
<option>Area A
<option>Area B</select>
Question by:cybeh
    LVL 10

    Expert Comment

    Hi, cybeh.

    I'm not seeing the Combobox you mention; maybe I'm just missing it, but I am being redirected to this URL:

    In any event, the usual syntax to write to a form element value is:
         WebBrowser1.Document.Forms(0).Elements("cmbArea").Value = "Area A"

    LVL 1

    Author Comment


    Thanks for the reply. is just a sample.

    Please have a look on this form

    The code
    WebBrowser1.Document.Forms(0).Elements("cmbArea").Value = "Area A"
    will work if the page was coded with
    <select name="cmbArea">
    <option value="" selected>
    <option value = "Area A">Area A
    <option value = "Area B">Area B</select>

    Please advice.

    LVL 10

    Accepted Solution

    I see what you mean.  For "select-one" element types we can do the following:

        MsgBox WebBrowser1.Document.Forms(0).Elements(1).selectedIndex  'gives name of currently selected option
        WebBrowser1.Document.Forms(0).Elements(1).selectedIndex = 2        'sets drop-down to option 2, or "Area B".
    LVL 10

    Expert Comment

    By the way, full details on all such options can be found here: (it's in German, and the translation isn't perfect, but the code examples are excellent).
    LVL 10

    Expert Comment

    For those that don't speak German, you can go to, paste the URL above in the "Translate a web page" textbox, and much of the Web page will be translated. For the remainder, or to translate a small part of the text, drop it into the "Translate text" textbox of the Google page.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now