Consulting

Results 1 to 7 of 7

Thread: I Can't change <SELECT> html tag using VBA

  1. #1
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    4
    Location

    I Can't change <SELECT> html tag using VBA

    Hello,

    I can log-in on the system - but, when i try select the <SELECT> html tag using vba i get the error: 91
    I realize what <SELECT> tag is controlled with JavaScript and i cant proceed.

    Anyone, can i help me?


    HTML
    HTML Code:
    <select name="ctl00$cphPrincipal$ddlEmpresa" onchange="javascript:setTimeout('__doPostBack(\'ctl00$cphPrincipal$ddlEmpresa\',\'\')', 0)" id="ctl00_cphPrincipal_ddlEmpresa" style="background-color:#EBEBEB;border-color:#E2E2E2;border-width:1px;border-style:Solid;width:140px;"><option selected="selected" value="">Selecionar Item...</option><option value="4">Pessoa Jurídica</option>
    I need to change de select's state to the value 4

    HTML + VBA CODE in Attachments

    Sorry for my bad english! Thanks!
    Attached Files Attached Files

  2. #2
    try using the fireevent method of the select element, after changing its value

  3. #3
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    4
    Location
    I did try like this:

    ie.document.getElementById("ctl00_cphPrincipal_ddlEmpresa").selectedIndex = 4
    ie.document.getElementById("ctl00_cphPrincipal_ddlEmpresa").FireEvent ("onchange")

    *ctl00_cphPrincipal_ddlEmpresa - <SELECT> ID

    It doesn't works - But <SELECT> stay empty instead the default value.

    Anybody knows what can be?

    Thanks

  4. #4
    ie.document.getElementById("ctl00_cphPrincipal_ddlEmpresa").selectedIndex = 4
    according to the sample file posted above there is only 2 items for selection
    only valid values for selected index would be 0 and 1, test for yourself

  5. #5
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    4
    Location
    westconn, Thank YOU!
    Works!

  6. #6
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    4
    Location
    Just one more question, if the <SELECT> tag is disabled, can i select? If not, have a way to do this?

  7. #7
    can i select?
    did you test? you should still be able to change values by code

    If not, have a way to do this?
    i would assume that you can enable by code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •