pressing a button in an ie page using vba

9,533

Just an FYI BruceWayne's suggesting worked for me but I just had to change (0) to (1).

IE.document.getElementsByName("Action")(1).Click

Share:
9,533

Related videos on Youtube

Eric
Author by

Eric

Learning and getting better at VBA.

Updated on September 18, 2022

Comments

  • Eric
    Eric over 1 year

    I've been trying to manipulate an internal website using vba but I have run into a problem. Currently, my script below opens the webpage and enters the values of cell a1 in sheet1 into the text box on the webpage. My problem is when I try to click on the search button I get the following message "run time error 438 Object doesn't support this property or method". I have tried a few different ways but none work. Also I have added the button properties when I inspect element. Thanks!

    <input name="Action" onclick="this.disabled=true; this.form.submit();" type="submit" value="Search">
    
    
    Sub autoIE()
    
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    
    IE.navigate "webpage.com"
    
    IE.Visible = True
    
    While IE.Busy
    DoEvents
    Wend
    
    IE.document.all("lookupNumberId").Value = ThisWorkbook.Sheets("Sheet1").Range("a1")
    
    IE.document.all("Action").Click 'error 438
    
    IE.document.getElementByName("Action").Click 'error 438
    
    End Sub
    
    • BruceWayne
      BruceWayne almost 6 years
      Is there a single element with that name on the page?
    • Eric
      Eric almost 6 years
      Yes, that's the only element with that name.
    • BruceWayne
      BruceWayne almost 6 years
      Try IE.document.getElementsByName("Action")(0).Click
    • Yorik
      Yorik almost 6 years
      I think IE.document.getElementByName("Action") returns an array (or array-like collection), and then you'd need to figure out which item is the right one. If its the only one, you might insert (0) between ("Action") and .Click
    • Eric
      Eric almost 6 years
      I tried BruceWayne's suggesting and this time I did not get an error message but nothing happen. But I changed (0) to (1) and it worked. Thank you so much.
    • Rajesh Sinha
      Rajesh Sinha almost 6 years
      I think the code is looking for actual keypress event ! Tell me are you searching in WBK?