Assuming you already have an IE window defined, which in itself is a bit more complicated - I can elaborate on this if necessary:
Dim ieIEWindow As SHDocVw.InternetExplorer Dim sIEURL As String 'Set your IE Window sIEURL = ieIEWindow.LocationURL
To get the IE window, you will need to reference the Microsoft Internet Controls
library ( ieframe.dll
) in the VBA editor by going to Tools
=> References...
and selecting it from the list. If this item is not available, the .dll file for me is located in C:\Windows\System32\ieframe.dll
.
Once the link is installed, you will get access to the so-called SHDocVw
library in your code.
You can capture the IE window (assuming only one is open) using the following (unverified, modified / reduced from my own working code):
Public Function GrabIEWindow() As SHDocView.InternetExplorer Dim swShellWindows As New SHDocVw.ShellWindows Dim ieOpenIEWindow As SHDocVw.InternetExplorer Set GrabIEWindow = Nothing ' Look at the URLs of any active Explorer windows ' (this includes WINDOWS windows, not just IE) For Each ieOpenIEWindow In objShellWindows ' Check the IE window to see if it pointed ' to a web location (http) If Left$(ieOpenIEWindow.LocationURL, 4) = "http" Then ' If so, set this window as the one to use. ' This will need to be modified to create ' a list if you want to select from more ' than one open window ' Optional grab the HWND for later reference... Dim lWindowID As Long lWindowID = ieOpenIEWindow.HWND Set GrabIEWindow = ieOpenIEWindow Exit Function End If Next OpenIEWindow End Function
The above can also be modified to select multiple open IE windows.
Gaffi source share