How to open multiple tabs in Internet Explorer with VBS ?

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

How to open multiple tabs in Internet Explorer with VBS ?

Post by hackoo » Sat Dec 07, 2013 7:50 am

Hi ;)
I'm Looking for how to open multiple tabs in Internet Explorer with a vbscript? any idea? I can do it with separate windows but not with tabs ?
I show you what i did so far :
VBScript Code
Double-click the code block to select all.
Option Explicit
Dim Titre,MyLogin,MyPassword,IE
MyLogin = "Hackoo"
If CheckConnectionInternet() = True Then 
'****************************************************
	'Connexion au site DVP
	Titre = "Connexion vers le site developpez.net"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionDVP(MyLogin,MyPassword)
'****************************************************
	'Connexion au site SFR
	Titre = "Connexion vers le site sfr.fr"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionSFR(MyLogin,MyPassword)
'****************************************************
	'Connexion au Gmail
	Titre = "Connexion vers le site Gmail"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionGmail(MyLogin,MyPassword)
'****************************************************
	'Connexion au Yahoo Mail
	Titre = "Connexion vers le site Yahoo Mail"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionYahooMail(MyLogin,MyPassword)
End if
'****************************************************
Function Boite2Saisie(Titre,MyLogin,MyPassword)
	Dim objIE,WS,ScreenWidth,ScreenHeight
	Set WS = CreateObject("Wscript.Shell")
	Set objIE = CreateObject("InternetExplorer.Application")
	objIE.Navigate "about:blank"
	objIE.Document.Title = Titre & String(20,"*")
	objIE.ToolBar        = False
	objIE.Resizable      = False
	objIE.StatusBar      = False
	objIE.Width          = 380
	objIE.Height         = 220
	ScreenWidth = objIE.document.ParentWindow.screen.width 
	ScreenHeight = objIE.document.ParentWindow.screen.height
	objIE.Left = (ScreenWidth  - objIE.Width ) \ 2
	objIE.Top  = (ScreenHeight - objIE.Height) \ 2
	Do While objIE.Busy
		WScript.Sleep 200
	Loop
	objIE.Document.Body.InnerHTML = "<div align=""center""><p>Nom Utilisateur "_
	& "<br><input type=""text"" size=""20"" "_
	& "id=""Login"" value="& MyLogin &"></p>"_
	& "</p><p>Mot de passe<br><input type=""password"" size=""20"" "_
	& "id=""Password""></p><p><input type=" _
	& """hidden"" id=""OK"" name=""OK"" value=""0"">"_
	& "<input type=""submit"" value="" Connexion "" "_
	& "onclick=""VBScript:OK.Value=1""></p></div>"
	objIE.Document.Body.Style.overflow = "auto"
	objIE.Document.body.style.backgroundcolor="lightblue"
	objIE.Visible = True
	objIE.Document.All.Password.Focus
	On Error Resume Next
	Do While objIE.Document.All.OK.Value = 0
		WScript.Sleep 200
		If Err Then    
			IELogin = Array("","")
			objIE.Quit
			Set objIE = Nothing
			wscript.quit
		End if
	Loop
	On Error Goto 0
	MyLogin = objIE.Document.All.Login.Value
	MyPassword = objIE.Document.All.Password.Value
	objIE.Quit
	If MyPassword = "" Then Wscript.Quit
End Function
'********************************************************************************************************************
Sub ConnexionDVP(MyLogin,MyPassword)
	Dim IE,Helem
	Set IE = CreateObject("InternetExplorer.Application") 
	with IE
		.navigate "http://www.developpez.net/forums/login.php"
		.AddressBar = 1
		.Visible = 1
		.ToolBar = 1
		.StatusBar = 1
		Do While (.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = .document.getElementById("vb_login_username")
		Helem.Value = MyLogin
		Set Helem = .document.getElementById("vb_login_password")
		Helem.Value = MyPassword
		Set Helem = .document.Forms(1)
		Helem.Submit 
	End with
End Sub
'********************************************************************************************************************
Sub ConnexionSFR(MyLogin,MyPassword)
	Dim IE,Helem
	Set IE = CreateObject("InternetExplorer.Application") 
	with IE
		.AddressBar = 1
		.Visible = 1
		.ToolBar = 1
		.StatusBar = 1
		.navigate2 "https://www.sfr.fr/cas/login?service=ht ... =X_head_ec"
		Do While (.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = .document.getElementById("username")
		Helem.Value = MyLogin
		Set Helem = .document.getElementById("password")
		Helem.Value = MyPassword
		Set Helem = .document.Forms(1)
		Helem.Submit 
	End with
End Sub
'********************************************************************************************************************
Sub ConnexionGmail(MyLogin,MyPassword)
	Dim IE,Helem
	Set IE = CreateObject("InternetExplorer.Application") 
	with IE
		.navigate "https://accounts.google.com/ServiceLogi ... ail/&hl=fr"
		.AddressBar = 1
		.Visible = 1
		.ToolBar = 1
		.StatusBar = 1
		Do While (.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = .document.getElementById("Email")
		Helem.Value = MyLogin
		Set Helem = .document.getElementById("Passwd")
		Helem.Value = MyPassword
		Set Helem = .document.Forms(0)
		Helem.Submit 
	End with
End Sub
'********************************************************************************************************************
Sub ConnexionYahooMail(MyLogin,MyPassword)
	Dim IE,Helem,objElement
	Set IE = CreateObject("InternetExplorer.Application") 
	with IE
		.navigate "https://login.yahoo.com/config/login_ve ... fr&.src=ym"
		.AddressBar = 1
		.Visible = 1
		.ToolBar = 1
		.StatusBar = 1
		Do While (.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = .document.getElementById("username")
		Helem.Value = MyLogin
		Set Helem = .document.getElementById("passwd")
		Helem.Value = MyPassword
		For Each objElement In IE.Document.Forms("login_form").Elements
			If (LCase(objElement.Type) = "submit") Then
					objElement.Click
				Exit For
			End If
		Next
	End with
End Sub
'********************************************************************************************************************
	Function CheckConnectionInternet()
		Dim Boucle,strComputer,MsgTitre,objPing,objStatus,ws
		Set ws = CreateObject("wscript.Shell")
		Boucle = True
		While Boucle = True
			strComputer = "smtp.gmail.com"
			MsgTitre = "TEST DE CONNEXION INTERNET ET SMTP DE GMAIL"
			Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
			For Each objStatus in objPing
				If objStatus.Statuscode = 0 Then
'Ws.popup "TEST SMTP DE GMAIL EST OK . VOUS ETES CONNECTE A INTERNET ET LE SMTP DE GMAIL EST DISPONIBLE !","3",MsgTitre,64
					Boucle = False
					CheckConnectionInternet = True
					Exit Function
				else
					ws.popup "TEST SMTP DE GMAIL EST NO OK . VOUS N'ETES PAS CONNECTE A INTERNET ET LE SMTP DE GMAIL N'EST PLUS DISPONIBLE EN CE MOMENT !","3",MsgTitre,16
				End If
			Next
			wscript.sleep 60000
		Wend
	End Function
'*******************************************************************


User avatar
jvierra
Posts: 12958
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to open multiple tabs in Internet Explorer with VBS

Post by jvierra » Sat Dec 07, 2013 10:42 am

I couldn't find my example so here is a new one.
VBScript Code
Double-click the code block to select all.
Const navflags = 2048

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.Navigate2  "http://en.wikipedia.org/wiki/"
Do
    WScript.Sleep 100
Loop While IE.Busy

IE.Navigate2 "http://www.google.com", navflags
Do
    WScript.Sleep 100
Loop While IE.Busy

User avatar
hackoo
Posts: 103
Joined: Sat Jan 22, 2011 12:27 am

Re: How to open multiple tabs in Internet Explorer with VBS

Post by hackoo » Sat Dec 07, 2013 2:56 pm

Thank you for this code that worked great for me ;) but in my case i want now to put them in two diffrents Subs like that :
VBScript Code
Double-click the code block to select all.
Const navflags = 2048
Set IE = CreateObject("InternetExplorer.Application")
Call One
Call Two
'**********************************************
Sub One()
	IE.Visible = True
	IE.Navigate2  "http://en.wikipedia.org/wiki/"
	Do
		WScript.Sleep 100
	Loop While IE.Busy
end sub
'********************************************
Sub Two()
	IE.Navigate2 "http://www.google.com", navflags
	Do
		WScript.Sleep 100
	Loop While IE.Busy
End Sub
'**********************************************
So this it works for me but in my case no :?:
VBScript Code
Double-click the code block to select all.
Option Explicit
Const navflags = 2048
Dim Titre,MyLogin,MyPassword,IE
Set IE = CreateObject("InternetExplorer.Application")
MyLogin = "Hackoo"
If CheckConnectionInternet() = True Then 
'****************************************************
	'Connexion au site DVP
	Titre = "Connexion vers le site developpez.net"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionDVP(MyLogin,MyPassword)
'****************************************************
	'Connexion au site SFR
	Titre = "Connexion vers le site sfr.fr"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionSFR(MyLogin,MyPassword)
'****************************************************
	'Connexion au Gmail
	Titre = "Connexion vers le site Gmail"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionGmail(MyLogin,MyPassword)
'****************************************************
	'Connexion au Yahoo Mail
	Titre = "Connexion vers le site Yahoo Mail"
	Call Boite2Saisie(Titre,MyLogin,MyPassword)
	Call ConnexionYahooMail(MyLogin,MyPassword)
End if
'****************************************************
Function Boite2Saisie(Titre,MyLogin,MyPassword)
	Dim objIE,WS,ScreenWidth,ScreenHeight
	Set WS = CreateObject("Wscript.Shell")
	Set objIE = CreateObject("InternetExplorer.Application")
	objIE.Navigate "about:blank"
	objIE.Document.Title = Titre & String(20,"*")
	objIE.ToolBar        = False
	objIE.Resizable      = False
	objIE.StatusBar      = False
	objIE.Width          = 380
	objIE.Height         = 220
	ScreenWidth = objIE.document.ParentWindow.screen.width 
	ScreenHeight = objIE.document.ParentWindow.screen.height
	objIE.Left = (ScreenWidth  - objIE.Width ) \ 2
	objIE.Top  = (ScreenHeight - objIE.Height) \ 2
	Do While objIE.Busy
		WScript.Sleep 200
	Loop
	objIE.Document.Body.InnerHTML = "<div align=""center""><p>Nom Utilisateur "_
	& "<br><input type=""text"" size=""20"" "_
	& "id=""Login"" value="& MyLogin &"></p>"_
	& "</p><p>Mot de passe<br><input type=""password"" size=""20"" "_
	& "id=""Password""></p><p><input type=" _
	& """hidden"" id=""OK"" name=""OK"" value=""0"">"_
	& "<input type=""submit"" value="" Connexion "" "_
	& "onclick=""VBScript:OK.Value=1""></p></div>"
	objIE.Document.Body.Style.overflow = "auto"
	objIE.Document.body.style.backgroundcolor="lightblue"
	objIE.Visible = True
	objIE.Document.All.Password.Focus
	On Error Resume Next
	Do While objIE.Document.All.OK.Value = 0
		WScript.Sleep 200
		If Err Then    
			IELogin = Array("","")
			objIE.Quit
			Set objIE = Nothing
			wscript.quit
		End if
	Loop
	On Error Goto 0
	MyLogin = objIE.Document.All.Login.Value
	MyPassword = objIE.Document.All.Password.Value
	objIE.Quit
	If MyPassword = "" Then Wscript.Quit
End Function
'********************************************************************************************************************
Sub ConnexionDVP(MyLogin,MyPassword)
	Dim IE,Helem
	'Set IE = CreateObject("InternetExplorer.Application") 
	'with IE
		IE.navigate2 "http://www.developpez.net/forums/login.php"
		IE.AddressBar = 1
		IE.Visible = 1
		IE.ToolBar = 1
		IE.StatusBar = 1
		Do While (IE.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = IE.document.getElementById("vb_login_username")
		Helem.Value = MyLogin
		Set Helem = IE.document.getElementById("vb_login_password")
		Helem.Value = MyPassword
		Set Helem = IE.document.Forms(1)
		Helem.Submit 
	'End with
End Sub
'********************************************************************************************************************
Sub ConnexionSFR(MyLogin,MyPassword)
	Dim IE,Helem
	'Set IE = CreateObject("InternetExplorer.Application") 
	'with IE
		IE.AddressBar = 1
		IE.Visible = 1
		IE.ToolBar = 1
		IE.StatusBar = 1
		IE.navigate2 "https://www.sfr.fr/cas/login?service=ht ... ",navflags
		Do While (IE.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = IE.document.getElementById("username")
		Helem.Value = MyLogin
		Set Helem = IE.document.getElementById("password")
		Helem.Value = MyPassword
		Set Helem = IE.document.Forms(1)
		Helem.Submit 
	'End with
End Sub
'********************************************************************************************************************
Sub ConnexionGmail(MyLogin,MyPassword)
	Dim IE,Helem
	'Set IE = CreateObject("InternetExplorer.Application") 
	'with IE
		IE.navigate2 "https://accounts.google.com/ServiceLogi ... ",navflags
		IE.AddressBar = 1
		IE.Visible = 1
		IE.ToolBar = 1
		IE.StatusBar = 1
		Do While (IE.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = IE.document.getElementById("Email")
		Helem.Value = MyLogin
		Set Helem = IE.document.getElementById("Passwd")
		Helem.Value = MyPassword
		Set Helem = IE.document.Forms(0)
		Helem.Submit 
	'End with
End Sub
'********************************************************************************************************************
Sub ConnexionYahooMail(MyLogin,MyPassword)
	Dim IE,Helem,objElement
	'Set IE = CreateObject("InternetExplorer.Application") 
	'with IE
		IE.navigate2 "https://login.yahoo.com/config/login_ve ... ",navflags
		IE.AddressBar = 1
		IE.Visible = 1
		IE.ToolBar = 1
		IE.StatusBar = 1
		Do While (IE.Busy)
			WScript.Sleep 100
		Loop
		Set Helem = IE.document.getElementById("username")
		Helem.Value = MyLogin
		Set Helem = IE.document.getElementById("passwd")
		Helem.Value = MyPassword
		For Each objElement In IEIE.document.Forms("login_form").Elements
			If (LCase(objElement.Type) = "submit") Then
					objElement.Click
				Exit For
			End If
		Next
	'End with
End Sub
'********************************************************************************************************************
	Function CheckConnectionInternet()
		Dim Boucle,strComputer,MsgTitre,objPing,objStatus,ws
		Set ws = CreateObject("wscript.Shell")
		Boucle = True
		While Boucle = True
			strComputer = "smtp.gmail.com"
			MsgTitre = "TEST DE CONNEXION INTERNET ET SMTP DE GMAIL"
			Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
			For Each objStatus in objPing
				If objStatus.Statuscode = 0 Then
'Ws.popup "TEST SMTP DE GMAIL EST OK . VOUS ETES CONNECTE A INTERNET ET LE SMTP DE GMAIL EST DISPONIBLE !","3",MsgTitre,64
					Boucle = False
					CheckConnectionInternet = True
					Exit Function
				else
					ws.popup "TEST SMTP DE GMAIL EST NO OK . VOUS N'ETES PAS CONNECTE A INTERNET ET LE SMTP DE GMAIL N'EST PLUS DISPONIBLE EN CE MOMENT !","3",MsgTitre,16
				End If
			Next
			wscript.sleep 60000
		Wend
	End Function
'*******************************************************************
So can you explain me what is my mistake and what the diffrence between IE.navigate and IE.navigate2
Thank you !

Locked