Get existing IE via VBA

后端 未结 5 1134
醉梦人生
醉梦人生 2020-12-10 07:48

My goal is to scrape data off multiple webpages on the same site into Excel. I have these pages open in tabs within IE8. I have no other IE windows open.

I have trie

5条回答
  •  有刺的猬
    2020-12-10 08:16

    OK, so I notice a potential problem with the first method you attempt using the Shell object.

    You may have an incorrect value for the .FullName property. (when I debug and examin the ShellWindows collection, I see path ""C:\Program Files (x86)\Internet Explorer\"

    Function GetIE() As Object
    
    Dim ShellApp as Object, ShellWindows as Object, i as Long 
    Dim IEObject As Object
    
    Set ShellApp = CreateObject("Shell.Application")
    Set ShellWindows = ShellApp.Windows()
    
    For i = 0 To ShellWindows.Count - 1
        If InStr(ShellWindows.Item(i).FullName, "C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE") <> 0 Then
           Set IEObject = ShellWindows.Item(i)
           Exit For  'No need to continue....
        End If
    Next
    
    If IEObject Is Nothing Then Set IEObject = CreateObject("InternetExplorer.Application")
    
    Set GetIE = IEObject
    
    End Function
    

    You can put this function in your code, just tuck it away somewhere, then whenever you need IE you can call it like:

提交回复
热议问题