Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

First post. No idea how to do this. Never retrieved data from a website before. Can navigate through VBA to a page with options to open reports, but at this point everything goes from html to Javascript to open reports. How would I go about opening the report? No problems in navigating to the page or pulling down the data from the table

<div id='delivery_reports' class='menu' onMouseover='aMenu(this);'>
<table>

<tr>
<td nowrap><a href="javascript:handleHyperlink('finish.do')"
class="mainSubLink">finish Report</a></td>
</tr>


<tr>
<td nowrap><a href="javascript:handleHyperlink('start.do')"
class="mainSubLink">start Report</a></td>
</tr>


<tr>
<td nowrap><a href="javascript:handleHyperlink('control.do')"
class="mainSubLink">control report</a></td>
</tr>


<tr>
<td nowrap><a href="javascript:handleHyperlink('data_start.do')"
class="mainSubLink">data start Report</a></td>
</tr>

</table>
</div>

How would i navigate to the control report for example?

Any help appreciated, thankyou

share|improve this question
up vote 1 down vote accepted

You can use the IE.Navigate method (assuming here that IE is your InternetExplorer object). You would do something like IE.Navigate "javascript:handleHyperlink('control.do')"

It's important to note that the page's HTML document will be reloaded (or rather, it was the one time I needed to use this), therefore any variables you have referencing HTML Elements on the page will have to be re-assigned after you use the Navigate method.

A more complete example:

Sub Test()
    Dim ie As InternetExplorer
    Dim doc As HTMLDocument

    Set ie = New InternetExplorer

    ie.Navigate "http://www.yoururl.com"

    'Wait for page to load
    Do While ie.Busy Or Not ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop

    Set doc = ie.document

    'Do whatever manipulation of the HTML document you need

    ie.Navigate "javascript:handleHyperlink('control.do')"

    'Wait for page to load
    Do While ie.Busy Or Not ie.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop

    'Reassign document
    Set doc = ie.document

    'Further manipulation

End Sub

This is just how I've found to do it based on making some code work for my own needs. There may be an even better way.

Addendum

You can execute JavaScript functions by using two methods (that I know of). The first is the execScript and the other is FireEvent. Remember that IE is your InternetExplorer object.

execScript

IE.document.all.Item 
Call IE.document.parentWindow.execScript("handleShowAllLines()", "JavaScript")

Additionally, since the js code is tied to a button, you can also use the FireEvent as such:

IE.Document.GetElementsByTagName("showAllLinesButton").Item(0).FireEvent("onclick")

This method assumes that there is only one button with the name "showAllLinesButton". If that is not the case, you'd have to adjust the index of 0 in the .Item(0) to be the index of the correct button that needs clicked.

I have not tested either method, and I am not completely sure of the advantages/drawbacks of one approach over the other.

share|improve this answer
    
Thankyou @JoshuaRoss, worked perfectly. function handleShowAllLines() { document.gloReportForm.showAllLinesButton.disabled=true; handleLink(); } <input type="button" name="showAllLinesButton" value="Show All Lines" onclick="handleShowAllLines();"/> How would I call on this? – jc123456 Aug 6 '14 at 10:32
    
I think there are two ways to do it, I'll update my answer. – Soulfire Aug 6 '14 at 13:41
    
Thankyou! sadly this time both pieces of your second solution code produced an error :( – jc123456 Aug 6 '14 at 19:04
    
May I have the URL of the website you are trying to do this on? That's the only way I will for sure be able to test. Sorry that my additions didn't help! – Soulfire Aug 6 '14 at 19:55
    
Oh dear, the site is private and passworded. Only accessible from certain computers also. Is there anything i could provide to help ascertain why it isn't working? – jc123456 Aug 7 '14 at 18:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.