Scrolling down a web page using VBA

M

M G

Hi,

I wish to be able to do the following things on a web page inside an Internet Explorer instance.
I would appreciate it if you could give me some guidance on that.

1. Scroll down or right on the page
2. Go to a specific location on the web page (say at a word or phrase), scrolling down, up, right or left. I want the focus of the window at that location.

I am using the following code to open a specific webpage. The IE window does NOT open in the maximized form. I want the page to automatically scroll down to the RATES section on the page.

VBA code:

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.Navigate "http://finance.yahoo.com/?
Do While IE.Busy: DoEvents: Loop


Thanks,

MG.

EggHeadCafe - Software Developer Portal of Choice
Excel macro for creating and manipulating charts
http://www.eggheadcafe.com/tutorial...5d-0cc6f4b06182/excel-macro-for-creating.aspx
 
T

Tim Williams

When you want this type of stuff it's best to start searching for javascript
snippets you can convert to VBA

http://radio.javaranch.com/pascarello/2005/01/09/1105293729000.html

This worked for me (but not consistently without the Wait line...)

Tim

'*************************
Option Explicit

Sub Tester()

Dim IE, doc, el
Dim X As Integer, Y As Integer

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.Navigate "http://finance.yahoo.com/?"

Do While IE.Busy: DoEvents: Loop
Application.Wait Now + TimeSerial(0, 0, 3)

Set doc = IE.document
Set el = doc.getElementById("rates_tabs")
X = 0
Y = 0

Do While Not el Is Nothing
X = X + el.offsetLeft
Y = Y + el.offsetTop
Debug.Print X, Y
Set el = el.offsetParent
Loop

doc.parentwindow.scrollTo X, Y

End Sub
'*********************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top