In my case there will normally be many open IE windows, but I want to extract some info. from one of these.In this ex. GOOGLE.
Then line: InStr("GOOGLE", IECaption) > 0 always return 1 no matter what IE instance I am looking at and the IECaption is always empty.
Code:
' Reference to
' Microsoft internet control
' microsoft html object lib.
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Sub Test()
Dim sText As String * 255
Dim IECaption As String
Dim SW As SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer
Set SW = New ShellWindows
Static lHwnd As Long
'Loop through all the shell windows on the desktop
For Each IE In SW
If TypeOf IE.Document Is HTMLDocument Then
IECaption = UCase(Left$(sText, GetWindowText(lHwnd, ByVal sText, 255)))
If InStr("GOOGLE", IECaption) > 0 Then
' Code for fetching info goes here
MsgBox IE.LocationName
End If
End If
Next IE
Set SW = Nothing
End Sub
What am I doing wrong ?
Cheers Karsten