herilane
12-10-2005, 10:55 AM
Internet Explorer supports automation, but GetObject isn't very useful for getting hold of existing IE windows - partly because IE windows are based on the same class as Windows Explorer windows, and partly because you can't specify which window you want based on a path name, as you can for other applications. (Not that I know of, at least.)
This simple procedure avoids GetObject and instead loops through all open IE and WE windows. You can use LocationURL and/or LocationName to find the IE window that you require. Not my own invention, but I find it very useful and underpublicized.
This requires a reference to Microsoft Internet Controls and to Microsoft Shell Controls and Automation.
Sub ListShellWindows()
'Get all currently open IE and Explorer windows
'For IE windows, get location. For WE windows, get path.
Dim objShell As Shell
Dim objIE As InternetExplorer
Dim objExplorer As ShellFolderView
Dim obj As Object
Set objShell = New Shell
For Each obj In objShell.Windows
If TypeName(obj.Document) = "HTMLDocument" Then
Set objIE = obj
Debug.Print objIE.LocationURL
Else
Set objExplorer = obj.Document
Debug.Print objExplorer.FocusedItem.Path
End If
Next obj
End Sub
This simple procedure avoids GetObject and instead loops through all open IE and WE windows. You can use LocationURL and/or LocationName to find the IE window that you require. Not my own invention, but I find it very useful and underpublicized.
This requires a reference to Microsoft Internet Controls and to Microsoft Shell Controls and Automation.
Sub ListShellWindows()
'Get all currently open IE and Explorer windows
'For IE windows, get location. For WE windows, get path.
Dim objShell As Shell
Dim objIE As InternetExplorer
Dim objExplorer As ShellFolderView
Dim obj As Object
Set objShell = New Shell
For Each obj In objShell.Windows
If TypeName(obj.Document) = "HTMLDocument" Then
Set objIE = obj
Debug.Print objIE.LocationURL
Else
Set objExplorer = obj.Document
Debug.Print objExplorer.FocusedItem.Path
End If
Next obj
End Sub