Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open multiple tabs in Internet Explorer with VBS ?

Status
Not open for further replies.

crackoo

Programmer
Feb 17, 2011
132
TN
Hi [peace]
I got this code from the net that worked great for me [2thumbsup]
Code:
Const navflags = 2048
Set IE = CreateObject("InternetExplorer.Application")
Call One
Call Two
'**********************************************
Sub One()
	IE.Visible = True
	IE.Navigate2  "[URL unfurl="true"]http://en.wikipedia.org/wiki/"[/URL]
	Do
		WScript.Sleep 100
	Loop While IE.Busy
end sub
'********************************************
Sub Two()
	IE.Navigate2 "[URL unfurl="true"]http://www.google.com",[/URL] navflags
	Do
		WScript.Sleep 100
	Loop While IE.Busy
End Sub
'**********************************************
So this it works for me but in my case no ?

Code:
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=""code: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 "[URL unfurl="true"]http://www.developpez.net/forums/login.code"[/URL]
		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 "[URL unfurl="true"]https://www.sfr.fr/cas/login?service=https%3A%2F%2Fwww.sfr.fr%2Faccueil%2Fj_spring_cas_security_check&sfrintid=V_nav_ec#sfrclicid=X_head_ec",navflags[/URL]
		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 "[URL unfurl="true"]https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/&hl=fr",navflags[/URL]
		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 "[URL unfurl="true"]https://login.yahoo.com/config/login_verify2?.intl=fr&.src=ym",navflags[/URL]
		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 how can i open multiple tabs with my code ? and what the diffrence between IE.navigate and IE.navigate2
Thank you !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top