Consulting

Results 1 to 7 of 7

Thread: Excel Button IE Automation

  1. #1

    Excel Button IE Automation

    Evening! New to forum so take it easy on me!

    Learnt loads off here already but stuck on one thing - the GetelementbyID!

    Using Excel to open up Website, log in, pull of report.

    There are two buttons on the website - 'Display' and 'Excel'
    Display Code:
    <button id="Display_Button" language="javascript" onmouseup="className='Highlight';" onmouseleave="className='';" onmouseover="Hand(this)" onclick="if (FT_FinalTest()) { __doPostBack('Display','') }" class="" style="height: 22px; width: 75px; z-index: 1000; left: 942px; top: 130px; position: absolute; cursor: pointer;" tabindex="25" onmouseenter="className='Highlight';Hand(this)" onmousedown="className='Clicked';">Display</button>
    Excel Code:
    <button id="Excel_Button" language="javascript" onmouseup="className='Highlight';" onmouseleave="className='';" onmouseover="Hand(this)" class="" style="height: 22px; width: 75px; z-index: 1000; left: 942px; top: 98px; position: absolute; cursor: pointer;" tabindex="26" onmouseenter="className='Highlight';Hand(this)" onmousedown="className='Clicked';" doonclick="__doPostBack('Excel','')">Excel</button>
    I use the below code to click Display and it works fine
     ie.document.getElementById("Display_Button").Click
    Now to click the Excel Button I would have assumed swapping the Display_Button out for Excel_Button would work, but it doesn't

    Am I missing something? Does a Reference need to be ticked that isn't already?
    Displays the error - Run Time Error 5002 - Application defined or Object Defined Error
    I have tried numerous methods such as Set A = ie.document.getElementById("Excel_Button") followed by A(0). click and submit, along with getelementsbyclassname but to no avail

    Many thanks for any help

    Regards

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    I know nothing of html, but have, in the past, looked at scraping the web for stuff.
    Looking at those two long bits of html, I look for differences and the only differences of note are that for the Display there is included:
    onclick="if (FT_FinalTest()) { __doPostBack('Display','') }"

    and for Excel:
    doonclick="__doPostBack('Excel','')"

    There is no onclick for excel and no doonclick for Display

    Fantasyland: I wonder if there's a
    ie.document.getElementById("Display_Button").doOnClick
    or some such!

    Why don't you tell us what the url actually is and perhaps include some of your code so we can experiment with them?


    edit post posting: more fantasy - .FireEvent("doonClick") ???

    I got that from http://stackoverflow.com/questions/1...n-vba-vbscript
    see if the one answer can help too.
    Last edited by p45cal; 02-25-2017 at 06:30 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3

    P45cal

    Evening P45cal -

    Unfortunately cant post the URL and there's not much else to the code that directly relates to this

    As i said it works fine clicking the Display button just doesn't recognize the Excel button - i tried the several onclick codes but nothing happens

    Works with SendKeys but attempting at all costs to avoid the using of them! I have tried focusing on the button first then click but not having any of it

    I feel like a doonclick alternative would work but just cant work it out

    Thanks for the help anyways!

  4. #4
    Evening p45cal and anyone else reading

    Managed to crack it using code below (Not my code - but doesn't allow me to post link)

    ie.navigate "javascript:__doPostBack('Excel','')"

    Works perfect!

    Thanks for the help

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Interesting, you can post the url by leaving off the http:// bit at the front.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    mrexcel.com/forum/excel-questions/502298-need-help-regarding-ie-automation-using-visual-basic-applications.html

    Post by 'headhair'

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by shaine321 View Post
    mrexcel.com/forum/excel-questions/502298-need-help-regarding-ie-automation-using-visual-basic-applications.html

    Post by 'headhair'
    Thats' worth bookmarking! Thanks.
    Could you post the url that you were trying to get data from?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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