Input box

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
784
Office Version
  1. 365
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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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
 
Upvote 0
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
 
Upvote 0
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]
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.

 
Upvote 0
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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top