VB Code to Fill Up LogIn Realm

Stonesteel

Board Regular
Joined
Apr 27, 2010
Messages
81
Greetings!

Can anyone help me how to make a vb code that will fill up the login realm when I click a command button? A have a sample here of scenario.

1. First is I have a command button that when I click, it will direct me to the webpage.

Code:
Code:
[FONT=Courier New][COLOR=blue]Sub ip_address()[/COLOR][/FONT]
 
[FONT=Courier New][COLOR=blue] File = "http://" & ActiveCell.Offset(0, 1).Value & ":1080/main.cgi?mac_esn=" & ActiveCell.Value & ""[/COLOR][/FONT]
 
[FONT=Courier New][COLOR=blue]  Call ShellExecute(0&, vbNullString, File, _[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]     vbNullString, vbNullString, vbNormalFocus)[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]End Sub[/COLOR][/FONT]

Image:
http://img171.imageshack.us/img171/4786/activecell.jpg
activecell.jpg


When I click the command button, this will be the url that I will be directed to, url will depend on the value of ActiveCell.Value and ActiveCell.Offset(0, 1)

http://img27.imageshack.us/img27/711/activecell2.jpg
activecell2.jpg


2. Now I will be on the index of the webpage which has a login realm,.

http://img822.imageshack.us/img822/9246/canopyrealm.jpg
canopyrealm.jpg


this is the html code for the login realm.


<form action='login.cgi' method='post' id='quickform'>
<div class='menu' id='quicklogin'>
<input type='hidden' name='mac_esn' value='0a003ef96923' />
<input type='hidden' name='Session' value='0' />
Username: <input type='text' name='CanopyUsername' id='CanopyUsername' /><br/>
Password: <input type='password' name='CanopyPassword' id='CanopyPassword'/><br/>
<input type='submit' value='Login' name='login' id='loginbutton' />
<input type='hidden' value='submit' name='webguisubmit' />
</< div></< color="purple" form>

and this is the username and password that I will be using for example,

Username: sm_inst58132806 (let's say this is located at cell C2)
Password: G4p5n0Xg (let's say this is located at cell D2)

3. Now what I want is to have a code that when I click the command button:

a. will direct me to the webpage
b. automation that will fill up the login realm with given username and password
c. after filling up the realm, will automatically click the submit button and will be directed to the main index.

http://img100.imageshack.us/img100/1592/loginsuccess.jpg
loginsuccess.jpg


hope you could help me on this, I know some of you already knew what code to use when it comes to this one.
 
Stonesteel

If you can capture the link, you shouldn't need to capture the session.
Code:
Set divMenu = IE.Document.GetelementbyID("menu")
 
Set lnkConfig = divMenu.GetelementsByTagName("A")(1)
 
lnkConfig.Click

norie, can you specify where to place the code and what to follow before and after that code so I can test it? thanks
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
StoneSteel

That code is just a suggestion of how it might be done, based on the HTML you posted.

Without access to the page it's hard to test if it will work.
 
Upvote 0
I was thinking something similar.

The div containing the menu has id="menu". My suggestion would have been:
.Document.getElementById("menu").Item(2).Click


If that doesn't work an alternative approach would be to loop through the url's on the page looking for one containing the text "Configuration".

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] LaunchWebPage([COLOR=darkblue]ByRef[/COLOR] sUrl [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], _
                          [COLOR=darkblue]ByVal[/COLOR] sUsername [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], _
                          [COLOR=darkblue]ByVal[/COLOR] sPassword [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR])
 
    [COLOR=darkblue]Dim[/COLOR] objIE [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] sSession [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=red]Dim i As Long[/COLOR]
 
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] Err_Hnd
 
    [COLOR=darkblue]Set[/COLOR] objIE = CreateObject("InternetExplorer.Application")
 
    [COLOR=darkblue]With[/COLOR] objIE
      .Navigate sUrl
      [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] .Busy: DoEvents: [COLOR=darkblue]Loop[/COLOR]
      [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] .ReadyState <> 4: DoEvents: [COLOR=darkblue]Loop[/COLOR]
      .Visible = [COLOR=darkblue]True[/COLOR]
 
      .Document.getElementById("CanopyUsername").Value = sUsername
      .Document.getElementById("CanopyPassword").Value = sPassword
      .Document.getElementById("loginbutton").Click
 
      [COLOR=green]'wait for the Home page to load[/COLOR]
      [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] .Busy: DoEvents: [COLOR=darkblue]Loop[/COLOR]
      [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] .ReadyState <> 4: DoEvents: [COLOR=darkblue]Loop[/COLOR]
 
[COLOR=red]     For i = 1 To .Document.all.Length[/COLOR]
[COLOR=red]       If .Document.all.Item(i).innertext = "Configuration" Then[/COLOR]
[COLOR=red]           .Document.all.Item(i).Click[/COLOR]
[COLOR=red]           Exit For[/COLOR]
[COLOR=red]       End If[/COLOR]
[COLOR=red]     Next i[/COLOR]
 
      [COLOR=green]'.Document.getElementById("SubUpkBitCreditRate").Value = 111[/COLOR]
      [COLOR=green]'.Document.getElementById("SubDwnkBitCreditRate").Value = 222[/COLOR]
 
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
Err_Hnd: [COLOR=green]'(Fail gracefully)[/COLOR]
    objIE.Visible = [COLOR=darkblue]True[/COLOR]
    [COLOR=darkblue]Set[/COLOR] objIE = [COLOR=darkblue]Nothing[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
yahoo! it worked! :D

now one last thing that I cannot get since this morning is the submit button, I don't know how to make the code for the submit button to function, it doesn't have an id. can you we make a code for this, its html code is:

div class='buttons'>
input type='submit' value="Save Changes" name="ok"/>
/div>

this is the last one.
 
Upvote 0
It doesn't have an id but it does have a name.

Try
Code:
.Document.getElementById("[COLOR=red]ok[/COLOR]").Click
 
Upvote 0
PS
For information only.

Going back to a previous post.
The div containing the menu has id="menu". My suggestion would have been:
.Document.getElementById("menu").Item(2).Click

The id we need would not be the division, but the ul (unordered list) containing the menu.

[edit] posting html didn't work
Then
.Document.getElementById("ul-id").Item(2).Click
should work.


But, unfortunately, it is not common practice to assign id's to lists in html.
 
Upvote 0
PS
For information only.

Going back to a previous post.


The id we need would not be the division, but the ul (unordered list) containing the menu.

[edit] posting html didn't work
Then
.Document.getElementById("ul-id").Item(2).Click
should work.


But, unfortunately, it is not common practice to assign id's to lists in html.

Sir bertie, I just used the alternative one, looking for one containing txt. and is now working. I just thought it would be much easier than the first one. :)
 
Upvote 0
sir bertie, and Norie, thank you so much for your help, my project is now finished and I am currently using it. Again, thank you very much for the time you've shared to finish this project. :)
 
Upvote 0

Forum statistics

Threads
1,216,045
Messages
6,128,484
Members
449,455
Latest member
jesski

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