Domanda

I am not using a WebBrowser control, I'm trying to get the process of IE in a variable in order to control it.

My goal is to automatically scroll down the page if needed. Here's some more information on how I start IE with my code:

    Dim IE As SHDocVw.InternetExplorer

    IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate("C:\rptStatusProd.xml") 'load web page google.com

    While IE.Busy
        Application.DoEvents()  'wait until IE is done loading page.
    End While

    IE.FullScreen = True

That doesn't let me control IE though... Is there a way to do it so that I can scroll down the page? I want to scroll up / down the page automatically because a web page will be on display throughout the company televisions and if there's too much data on the web page, it must scroll down to view it.

È stato utile?

Soluzione

It isn't pretty ... but it's something. It will scroll to the top of the page and back down to the bottom. I am lucky because there is no way I'll have enough items in my web page to display the in between. This worked for me:

Imports mshtml

Sub Main()
    Dim IE As SHDocVw.InternetExplorer

    IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate("C:\rptStatusProd.xml") 'load web page

    While IE.Busy
        Application.DoEvents()  'wait until IE is done loading page.
    End While

    IE.FullScreen = True

    Dim doc As HTMLDocumentClass = IE.Document
    Dim myProcesses() As Process
    myProcesses = Process.GetProcessesByName("iexplore")

    While myProcesses.Count > 0
        Try
            doc.activeElement.scrollIntoView(True) 'Scroll to top
            System.Threading.Thread.Sleep(5000)
            doc.activeElement.scrollIntoView(False) 'Scroll to bottom
            System.Threading.Thread.Sleep(5000)
        Catch COMEx As System.Runtime.InteropServices.COMException
            'RPC Server unavailable, Internet explorer was closed
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End While
End Sub
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top