Input box

josros60

Active Member
Joined
Jun 27, 2010
Messages
481
Hi,

I have the code below that I use to log in automatically into the website, how can i add input box in the code to ask me for the username and password and once i enter them to log in, thanks.


here is the code:

Code:
Sub login()Dim IE As Object
  Dim HTMLDoc As Object
  Dim objCollection As Object
 
  Const navOpenInNewTab = &H800
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE.Navigate "https://secure.shawbusinesssolutions.ca/html/billing_system_login.jsp"


  Do While IE.Busy Or IE.ReadyState <> 4: Loop


  Set HTMLDoc = IE.Document


  With HTMLDoc
  HTMLDoc.getElementById[B]("username_input_occ")[/B].Value = "4555-0001"
  HTMLDoc.getElementById([B]"password_input"[/B]).Value = "otherwise"
  End With




  Set objCollection = IE.Document.getElementById("signin_submit")
  objCollection.Click


End Sub
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
677
like this?
Code:
Sub login()
Dim IE As Object
  Dim HTMLDoc As Object
  Dim objCollection As Object
  Dim myUsername As Variant
  Dim myPass As Variant
  
     myUsername = InputBox("Enter Username")
    myPass = InputBox("Enter Password")
    
  Const navOpenInNewTab = &H800
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE.Navigate "https://secure.shawbusinesssolutions.ca/html/billing_system_login.jsp"




  Do While IE.Busy Or IE.ReadyState <> 4: Loop




  Set HTMLDoc = IE.Document




  With HTMLDoc
  HTMLDoc.getElementById("username_input_occ").Value = myUsername
  HTMLDoc.getElementById("password_input").Value = myPass
  End With








  Set objCollection = IE.Document.getElementById("signin_submit")
  objCollection.Click




End Sub
 

josros60

Active Member
Joined
Jun 27, 2010
Messages
481
thank you very much works good.

i have 7 accounts with the same company and they have same password how can i have the default password in the box and just type the username.

and i have other differents account and I have to log in at the end of the month to print invoices how can i have list box or something to ask besides username and pw the site.

thanks again
 

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
677
just remove:
Code:
myPass = InputBox("Enter Password")
and have the password part filled in by default:

Code:
HTMLDoc.getElementById("password_input").Value = ("password")
dont know what you mean with listbox though[/COLOR]
 

josros60

Active Member
Joined
Jun 27, 2010
Messages
481
Code:
thank you, it worked.

what i meant i have others websites to log in every month and i have spreadsheet with usernames and password and websites how can i add input box to ask for website and change these lines:

[CODE]IE.Navigate "ht
tps://secure.shawbusinesssolutions.ca/html/billing_system_login.jsp"

[/CODE] and add something like this

Code:
Dim myWebsite As Variant

thanks
 

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
677
Guessing you would need a separate macro for each site as the same elementIDs won't work on different sites.

But once you have the login scripts just assign each to a drop-down option on your list
 

josros60

Active Member
Joined
Jun 27, 2010
Messages
481
Yes, i would write a macro for each one cause of the element id, and I started already but once finish how can i assign each to a drop-down option on my list?
i have added macro to few of them could you please show me how to assign to drop-down list.


thank you.

 

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
677
assign to button
Code:
Sub Button2_Click()
If Range("L2").Value = 1 Then
Call Macro1
ElseIf Range("L2").Value = 2 Then
Call Macro2
ElseIf Range("L2").Value = 3 Then
Call Macro3
ElseIf Range("L2").Value = 4 Then
Call Macro4
End If
End Sub
Macro1 would be your first login script as above then so on

Insert form control (combobox)
Format control > set cell link (L2) and input list is your named range or list of sites
 
Last edited:

josros60

Active Member
Joined
Jun 27, 2010
Messages
481
thank you very much for all your help.

one question having some problem with internet explorer how can i change the code to open with chrome instead:

Code:
[COLOR=#333333]Sub login()[/COLOR]Dim IE As Object
  Dim HTMLDoc As Object
  Dim objCollection As Object
  Dim myUsername As Variant
  Dim myPass As Variant
  
     myUsername = InputBox("Enter Username")
    myPass = InputBox("Enter Password")
    
  Const navOpenInNewTab = &H800
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE.Navigate "https://secure.shawbusinesssolutions.ca/html/billing_system_login.jsp"




  Do While IE.Busy Or IE.ReadyState <> 4: Loop




  Set HTMLDoc = IE.Document




  With HTMLDoc
  HTMLDoc.getElementById("username_input_occ").Value = myUsername
  HTMLDoc.getElementById("password_input").Value = myPass
  End With








  Set objCollection = IE.Document.getElementById("signin_submit")
  objCollection.Click



 [COLOR=#333333]End Sub[/COLOR]

thank you again
 

Watch MrExcel Video

Forum statistics

Threads
1,095,950
Messages
5,447,515
Members
405,454
Latest member
Minglee

This Week's Hot Topics

Top