VBA - Open an explorer page, do a search in google images, give scrolldown to the bottom of the page and use the console

Asked

Viewed 299 times

1

I’m developing a VBA module to open google images, search "cement", scroll the page down to the end and then use the console to input some scripts into javscript.

The Code so far is as follows::

Sub Google()
Dim IE As Object
Dim Pesquisa As String

Pesquisa = "cimento"

Set IE = CreateObject("InternetExplorer.application")
With IE
    .Visible = True
    .Navigate ("https://www.google.com/imghp?q=" & Pesquisa)
    While .Busy Or .readyState <> 4:
        DoEvents:
    Wend

    waittime (1000)

    SendKeys "~", True
    SendKeys "{PGDN}", True
    .document.parentwindow.execScript "javascript_code()", "JavaScript"

End With

End Sub

Function waittime(ByVal milliSeconds As Double)
    Application.Wait (Now() + milliSeconds / 24 / 60 / 60 / 1000)
End Function

However, the page does not scroll down, which is of paramount importance for the script to work. I’ve searched a lot of places to do this, but they all come back to this same Sendkeys function. If anyone has any suggestions on how to input the explorer console, I’d appreciate it too. I haven’t been able to test this method yet.

Thank you for your attention.

1 answer

1


Good afternoon, you already have a problem like this, I believe this article can help you. The code that is described below worked in my case, I recommend you test it. I hope it has helped.

https://www.excelforum.com/excel-programming-vba-macros/531354-solved-launch-ie-browser-and-manage-vertical-scroll-bars.html

Sub LaunchIeAndManageVerticalScroll()
Const READYSTATE_COMPLETE& = 4&
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
    .AddressBar = False
    .MenuBar = False
    .Toolbar = False
    .Width = 600&
    .Height = 750&
    .Left = 0&
    .Top = 0&
    .navigate "www.yahoo.com"
    .resizable = True
    While Not .readyState = READYSTATE_COMPLETE
        DoEvents
    Wend
    .document.parentWindow.scroll 0&, 200&
    .Visible = True
End With
 Set ie = Nothing
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.