Consulting

Results 1 to 7 of 7

Thread: Run-time error '91' Click html button

  1. #1

    Run-time error '91' Click html button

    I am working in VBA trying to go to a link, then click a button to export to .xls. I am getting a run-time error though. The debug takes me to this:
    btnGo(0).Click
    but here is my entire code: (I have extra variables because I copied and pasted from another previous code.)
    Private Sub exportXLS()
    
    
        Dim I As Long
        Dim IE As Object
        Dim doc As Object
        Dim objElement As Object
        Dim objCollection As Object
        Dim btnGo As Object
    
    
        ' Create InternetExplorer Object
        Set IE = CreateObject("InternetExplorer.Application")
        IE.Visible = True
    
    
        ' Send the form data To URL As POST binary request
        IE.navigate "www.website.com"
    
    
        ' Wait while IE loading...
        Do While IE.Busy
            Application.Wait DateAdd("s", 1, Now)
        Loop
        
        Set btnGo = IE.Document.GetElementsByTagName("Javascript:doClick(17)")
            btnGo(0).Click
    
    End Sub
    html:
    <a href="Javascript:doClick(17)" onmouseover="return(doOver(17,1));" onmouseout="return(doOver(17,0));"><img name="save_xls" alt="Export XLS" title="Export XLS" width="24" height="24" border="0" src="http://dsmdc-cog-web1.mediacomcorp.com/cognos/ppwb/Icon24/save_xls.gif"></a>
    html for button image:
    <img name="save_xls" alt="Export XLS" title="Export XLS" width="24" height="24" border="0" src="http://dsmdc-cog-web1.mediacomcorp.com/cognos/ppwb/Icon24/save_xls.gif">

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    btnGo vs btnGo(0)

    why?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Quote Originally Posted by mancubus View Post
    btnGo vs btnGo(0)

    why?
    That’s just the syntax I found online. I’m only self taught. If I change that will it work?

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    not guaranteed.

    just try it.

    you'd better search it with "excel vba click a button on webpage" or similar keywords
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    Quote Originally Posted by mancubus View Post
    not guaranteed.

    just try it.

    you'd better search it with "excel vba click a button on webpage" or similar keywords
    I did dozens of searches, some used variables, some didn't. I'm just not familiar with the syntax for IE button clicks.

    I ran it without, and I got "Run-time error '438'; Object doesn't support this property or method." The website I am accessing is a secure website, does that have anything to do with it?

    If I run the code up until the
    btnGo.Click
    line, I can see the value assigned to the variable is "[object]". Is this what it should be?

  6. #6
    The more that I look at the HTML, I'm focusing on the javascript part. Is that going to affect anything? I'm running a simple scrape VBA to return values, but for some reason it won't return values of the "a" tag, its only returning values if its in "frameset."

  7. #7
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you should identify the button to be clicked

    some ideas:
    https://www.mrexcel.com/forum/excel-...ation-vba.html
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

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