-
Knowledge Base Approver
The King of Overkill!
VBAX Master
Gibbo,
Are you sure there is only going to be one IE window open, and zero explorer windows open? Automating IE can be done easily, however if there are multiple you may not get the one you want, and if you have an explorer windows open that could throw it for a loop. Take a look at http://www.vbaexpress.com/forum/showthread.php?t=11148 for some more information about it all.
Anyways, to show you how you can do this, set a reference to Microsoft Internet Controls in your vba project, then run the following:[vba]Sub GetIEWindows()
'Requires reference to Microsoft Internet Controls
Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer
'Establish link to IE application
Set SWs = New SHDocVw.ShellWindows
For Each vIE In SWs
If Left(vIE.LocationURL, 4) = "http" Then 'avoid explorer windows/etc this way
If MsgBox("IE Window found. The URL is:" & vbCrLf & vIE.LocationURL & vbCrLf & _
vbCrLf & "Do you want to see the html?", vbYesNo) = vbYes Then
'Show html in a msgbox
MsgBox vIE.Document.Body.innerHTML
'Or put it to a file
'dim vFF as long
'vff=freefile
'open "C:\thehtml.txt" for output as #vff
'print #vff,vie.document.body.innerhtml
'close #vff
End If
End If
Next
Set SWs = Nothing
Set vIE = Nothing
End Sub[/vba]You can see tht vIE.LocationURL is the way to get the URL you're looking for, but this shows you how to iterate through all IE windows (if the one you want will follow a certain pattern this should help) and how to avoid explorer windows (as well as get the HTML of the page you're looking at too).
Matt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules