2013-05-29 46 views
0

我不使用WebBrowser控件,我試圖在一個變量中獲取IE的過程以控制它。Autoscroll Internet Explorer

我的目標是在需要時自動向下滾動頁面。下面是我如何啓動IE我的代碼一些更多的信息:

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 

這並不讓我控制IE,雖然...有沒有辦法做到這一點,這樣我可以向下滾動頁面?我想自動向上/向下滾動頁面,因爲網頁將在整個公司電視上顯示,如果網頁上的數據太多,它必須向下滾動以查看它。

回答

2

這不是很漂亮......但它是某種東西。它將滾動到頁面的頂部並返回到底部。我很幸運,因爲我的網頁中沒有足夠的項目來顯示它們之間的方法。這工作對我來說:

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