3

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

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
Thankyou! sadly this time both pieces of your second solution code produced an error :(
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!
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.