PDA

View Full Version : Navigate Webiste and click on link/button using vba



Jamyhamy
08-30-2013, 05:12 AM
I have an internal website that I need to navigate to get to data, i.e along the left hand of the site, there are links/buttons that I need to click on (e.g a link called Dinvestment) which I would like to do using VBA. When viewing the source, it seems like it is using Java script and the following is the area of the code where I find the link/button name that I need to click: >http://www.vbaexpress.com/forum/img/hier/fc.pngDIVESTMENT http://www.vbaexpress.com/forum/img/hier/fc.pngBBB http://www.vbaexpress.com/forum/img/hier/fc.pngBBBIf I wanted to click on divestment link using VBA, I'm assuming the first line of the code (where the word "divestment" appears) is what I need to manipulate to access? Presumably by actioning/clicking the code '50002'? I know how to launch the website using vba, but not how to navigate it to click on the various link. Hope someone can help with the code.Thanks,JH

raj85
08-30-2013, 07:16 AM
You can use below code
place link/button ID in placeof ItemID, you can search that in view source.


IE.document.getelementbyid("itemID").click

provide your code for more help

Jamyhamy
08-30-2013, 09:28 AM
Thanks Raj. I'm not sure I understand as I have never worked with HTML or Java script ever before.Do you mean something like this, where 50002 is the onclick code associated with Divestment? ie.document.getelementbyid("50002").ClickThanksJH

a g
08-30-2013, 09:33 AM
You need to look at det HTML code. Hopefully they have given the link a unique id. Look for the Id paramter in the link code. example: <a href="somepage.htm" id="uniqueID" >Click me</a>, in this case the unique id is "uniqueId" and you can reference it as raj85 explained in the previus post.

Jamyhamy
09-17-2013, 09:15 AM
Gents,I am still struggling to locate the link. Is there a way I can paste the relevant lines of the HTML code here?This is the msg I tried sending earlier: (Hi, I have found the following line relating the Dinvesment link. How do I indentify the ID here that I need to manipulate please? Is it H50002? If so, to access this link would the VBA code be "IE.document.getelementbyid("H50002").click" Thanks JH HTML HERE BUT DOES NOT SHOW.