PDA

View Full Version : [SOLVED] Excel Button IE Automation



shaine321
02-24-2017, 04:22 PM
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

p45cal
02-25-2017, 06:05 AM
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/12583405/how-to-do-onclick-event-in-vba-vbscript
see if the one answer can help too.

shaine321
02-26-2017, 11:34 AM
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!

shaine321
02-26-2017, 01:44 PM
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

p45cal
02-26-2017, 01:58 PM
Interesting, you can post the url by leaving off the http:// bit at the front.

shaine321
02-26-2017, 02:04 PM
mrexcel.com/forum/excel-questions/502298-need-help-regarding-ie-automation-using-visual-basic-applications.html

Post by 'headhair'

p45cal
02-27-2017, 03:36 AM
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?