-1

I was trying to find a way to scroll (down, up) a webpage with vba.

I have a page where I need to fill in some information. This part is working. The only thing, it happens somewhere down there and I would like to see it happening so I need to scroll the window down in a way... is there a trick?

Thanks a lot!!!

QHarr
  • 83,427
  • 12
  • 54
  • 101
Uni YaMo
  • 21
  • 2
  • 5
  • What packages (references) are you using? Ex, if you're using selenium, this might help :http://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium – user3476534 Sep 12 '15 at 22:28

3 Answers3

1

You can execute javascript to scroll on the page e.g.

Option Explicit
Public Sub ScrollWindow()
    Dim ie As New InternetExplorer
    With ie
        .Visible = True
        .navigate "https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollBy"
        While .Busy Or .readyState < 4: DoEvents: Wend
        .document.parentWindow.execScript "window.scrollBy(0, window.innerHeight);", "javascript"
        Stop '<== Delete me
        .Quit
    End With
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101
0

Hello and thanks for your reply. I'm not using selenium.. But I did find a way to get around it: 1. Simply by using:

SendKeys "{Down}"

  1. But this wasn't accurate enough so I did this:

.Navigate "web-address" & "#location-name"

As stated when inspecting the element.

I hope my findings can be helpful for someone out there ;)

Thanks again for your reply!

Uni YaMo
  • 21
  • 2
  • 5
0

This is the code to scroll to the bottom of the page

Sub ScrollToDown()
    Url = "http://en.wikipedia.org/wiki/Main_Page"
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .navigate Url
        .Visible = True
        While ie.readyState <> 4: DoEvents: Wend
        .document.parentWindow.execScript "window.scrollTo(0, document.body.scrollHeight||document.documentElement.scrollHeight);", "javascript"
    End With
End Sub
antonshc
  • 1
  • 2