I am trying to find a way to read the Address bar from an open instance of Internet explorer into my program. I am not bothered as to how it is done. Can someone help please?
[email protected]
Printable View
I am trying to find a way to read the Address bar from an open instance of Internet explorer into my program. I am not bothered as to how it is done. Can someone help please?
[email protected]
Try this:
Code:Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD
Private Sub Command1_Click()
Dim lngIE As Long
Dim lngWrkArea As Long
Dim lngEditBox As Long
Dim strEditText As String
Dim lngEditLen As Long
Dim lngCaptionLen As Long
Dim strCaption As String
lngIE = FindWindowEx(0, 0, "IEFrame", vbNullString)
lngWrkArea = FindWindowEx(lngIE, 0, "WorkerW", vbNullString)
lngWrkArea = FindWindowEx(lngWrkArea, 0, "ReBarWindow32", vbNullString)
lngWrkArea = FindWindowEx(lngWrkArea, 0, "ComboBoxEx32", vbNullString)
lngWrkArea = FindWindowEx(lngWrkArea, 0, "ComboBox", vbNullString)
lngEditBox = FindWindowEx(lngWrkArea, 0, "Edit", vbNullString)
lngEditLen = SendMessage(lngEditBox, WM_GETTEXTLENGTH, 0, 0)
strEditText = Space(lngEditLen + 1)
If SendMessageStr(lngEditBox, WM_GETTEXT, lngEditLen, ByVal strEditText) Then
strEditText = Left(strEditText, InStr(strEditText, vbNullChar) - 1)
End If
lngCaptionLen = GetWindowTextLength(lngIE)
strCaption = Space(lngCaptionLen + 1)
If GetWindowText(lngIE, strCaption, lngCaptionLen + 1) Then
strCaption = Left(strCaption, InStr(strCaption, "- Microsoft Internet Explorer") - 1)
End If
MsgBox "The current URL: " & strEditText & vbCrLf & _
"Page Title: " & strCaption
End Sub