Get existing IE via VBA

后端 未结 5 1288
醉梦人生
醉梦人生 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:11

    Made some changes and it works now

             Function GetIE() As Object
    
                Dim ShellApp As Object, ShellWindows As Object
                Dim IEObject As Object
    
                Set ShellApp = CreateObject("Shell.Application")
    
                Set ShellWindows = ShellApp.Windows()
    
                Dim item As Object
                On Error GoTo 0
                Dim sName As String
    
                   For Each ObjWind In ShellWindows
                    'On Error Resume Next
                     If (Not ObjWind Is Nothing) Then
                        sName = ObjWind.Name
                         If sName = "Internet Explorer" Then
                            Set IEObject = ObjWind
                            Exit For  'No need to continue....
                         End If
                     End If
    
                    Next
    
                If IEObject Is Nothing Then Set IEObject = CreateObject("InternetExplorer.Application")
    
                Set ShellApp = Nothing
    
                Set GetIE = IEObject
    
                End Function
    

提交回复
热议问题