PDA

View Full Version : Solved: VBA HTML - how do I access this button?



musicgold
11-07-2009, 10:56 PM
Hi,
Please see the attached source code for a button on a website. I need to click the button using VBA.
As there is no unique id or name to the button, I am not able to access the button using the typical getelementbyid or getelementsbyname. Also there are more than one button with the class “header_button”
How can I access the button?


INPUT class="header_button" style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; BACKGROUND-IMAGE: url(images/header_button.gif); COLOR: navy; BACKGROUND-COLOR: #ffbb00" on click="printWithoutAnswer()" type="button" value="Without Answer" >

Oorang
11-09-2009, 09:50 AM
You could always loop through the Document.All collection and look for things of the right type with the right caption. Use a Generic object as the looping variable and TypeName to get it's specific type.

Although unless you have a reason for emulating the click, personally I'd just directly execute it's action "printWithoutAnswer()". You can do this directly using ie.Navigate "javascript:printWithoutAnswer()" Or if you prefer something less hackish you can use execScript:
'Untested
Dim ie As SHDocVw.WebBrowser
Dim doc As MSHTML.IHTMLDocument2
Set ie = New SHDocVw.InternetExplorer
ie.Navigate "http://www.yourSite.com"
Do Until ie.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Set doc = ie.Document
doc.parentWindow.execScript "printWithoutAnswer"
ie.Quit

musicgold
11-11-2009, 08:23 AM
Oorang,

Thanks a lot. It works fine.
Sorry for the delay in replying; the alert email was sitting in my spam box.