I was working on a project where I had the following requirement, and for a moment I thought, "Man, that's like a 5 min task for me!!". And it should have been!!!! Unfortunately though, I couldn't find the right document at the right time and it took me some time to achive what I wanted to achieve :-(
The task at my hand was...
1. Open a Page in Internet Explorer and wait for it to load completely.
2. Once the first page is loaded, Open a new Window and navigate to another Page.
3. Then, Open a new Tab in IE 7 and navigate to yet another page.
Since, I have not worked much into automation of Objects, I was looking for some ready made code, and after a little bit of struggle (which I didn't expect, honestly), I ended up with the following in VB6. Yes... VB6 :-) (I am yet to install VS.NET on my home PC after a recent format of the box!)
Okay, so here we go...
First things first! You will need to add a Reference using the Project->References for "C:\Windows\System32\shdocvw.dll". Just drop a command button and call it cmdDoMyTask.
Private Sub cmdDoMyTask_Click()
On Error GoTo ErrHandler
Dim objIE As SHDocVw.InternetExplorer
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate2 "http://www.microsoft.com/"
'Wait till the page is completely displayed!
'The following three lines are not needed if
'you don't want to wait for the 1st page to display completely
While objIE.ReadyState < 4
Sleep 100
Wend
'Open in new Window (u need to pass the value 1)
objIE.Navigate2 "http://www.live.com/", 1
'Open in new Tab (u need to pass the value 2048)
objIE.Navigate2 "http://www.msn.com/", 2048
Set objIE = Nothing
Exit Sub
ErrHandler:
Set objIE = Nothing
End Sub
By the way, here is the document which helped me out for the "Open in new Tab"! Phew!!!
I hope that helps,
Rahul