Running a web query when there is a user name and password

rca

Board Regular
Joined
Mar 1, 2005
Messages
182
Hi Everyone!

I'm trying to run a web query from a website that requires a user name and password.

Is it possible to do such a thing when the website has a user name and password?

Thank you,
Rachel :biggrin:
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
Sub myWebOpenPW()
'Open site if it requires a PassWord Model!
Dim IE As Object

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

'Go to this Web Page!
IE.Navigate "http://YourLoggOnPageAddress_GosHere"

'Check for good connection to web page loop!
Do
If IE.ReadyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop

'Wait for window to open!
Application.Wait (Now + TimeValue("0:00:01"))
'MsgBox "Done"
IE.Visible = True

'Send logg-on information!
'May need additional SendKeys as needed?
'Determine by the actual key-strokes needed!
SendKeys "UserID_GosHere", True
SendKeys "{TAB}", True
SendKeys "PassWord_GosHere", True
SendKeys "{ENTER}", True
End Sub
 

rca

Board Regular
Joined
Mar 1, 2005
Messages
182
Thank you Joe! That works! I just needed to add another statement:

SendKeys "{TAB}", True

in order to get the macro to work. So, now it works!

Just a question: the macro you suggested brings me to the main page. Across the top of the main page are a bunch of links. One of the links is called 'Reports'.

Is there a way for me to activate this link? If I can, activating this 'Reports' link will take me to another screen with a link called 'Statements'. When I click on this 'Statements' link, I see a 'Process' button that pops up. When I click on the 'Process' button, I see the report that I need.

How do I activate these links? And, is there a way for me to "press" the 'Process' button to activate this report? Is there a way to do these things?

Thank you so much!!!!
Rachel :biggrin: :biggrin:
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
After the sign-in code add an:

Application.Wait (Now + TimeValue("0:00:02"))

you may need to make the time longer?

Then send keys TAB untill you get to where you want to be, then send keys ENTER to select it.

Test this by Tabbing with your keyboard tab key to see if the web page was coded that way, first?
 

rca

Board Regular
Joined
Mar 1, 2005
Messages
182

ADVERTISEMENT

Hi! I have edited your code a little bit. It now looks like:

Code:
Sub OpenMyWebPage()

Dim IE As Object

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

IE.Navigate "https://www.myWebPage.com/default.asp"

'Check for good connection to web page loop!

Do
If IE.ReadyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop

'Wait for window to open!
Application.Wait (Now + TimeValue("0:00:02"))
'MsgBox "Done"
IE.Visible = True

'Send log-on information!

SendKeys "myUserName", True
SendKeys "{TAB}", True
SendKeys "myPassword", True
SendKeys "{ENTER}", True

End Sub

Here is my NEW problem. When I execute the above code, sometimes it works and sometimes it doesn't work. What do I mean by this?

For the times that it 'doesn't work', I have determined that:

1. the user name field on the web page is already populated
2. the above code 'sees' that the user name field is already populated
3. the code 'skips' the user name field and attempts to put the user name in the password field
4. an error on the webpage occurs because I'm trying to pass an incorrect password

When does this happen? It seems to happen if I DO NOT delete temporary internet files and/or 'clear forms' or 'clear passwords' (Tools | Internet Options | Content | Auto Complete)

But, it is not feasible for me to delete temp internet files and/or clear forms and clear passwords each time I want to run this macro.

Is there a way that we can edit the above code so that it:

1. Checks to see if the user name field on the webpage is populated
2. If the user name field is popluated, then
3. Proceeds directly to the password field and populates the password field with the password

Basically, we are just adding a check to see if the password field is already populated.

Is this possible?

Thank you so much!
Rachel :biggrin: :biggrin:
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
You can play with sending a: Ctrl+A [Select-All] 1st thing when you get to the page in IE. Then send : Delete to remove what is their?
Then see where a Tab takes you and go from their?

Also with more complex web work the Send Keys is not the best way to do it, API's, custom functions or "Nate O's" web query to work with the page is better! [Lot more avanced code to do though!]

http://www.mrexcel.com/board2/viewtopic.php?t=180837
 

rca

Board Regular
Joined
Mar 1, 2005
Messages
182

ADVERTISEMENT

When I navigate to the page, the user name field is populated and the cursor automatically focuses directly IN the password field (the cursor is flashing inside the field). If I hit Ctrl + A, nothing happens. Only if I click out of the password field will Ctrl + A allow me to select all (and then delete the user name). So, this method will not work. Can you think of anything else (other than Nate's very complicated code)?

Thank you,
Rachel

PS: I might have to use Nate's code based on the complexity of this problem.
 

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700
You're manipulating a form, so you want to figure out the name of the control in that form and simply pass a value to the textbox.

Check out the source and figure out if you can identify the form and control. :)
 

msvec

Board Regular
Joined
Feb 18, 2002
Messages
202
This code is great! Anyone know how to make IE open in a maximized state? That would be most helpful to me.

Thanks
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
You can try adding:


Application.Wait (Now + TimeValue("0:00:02"))
ActiveWindow.WindowState = xlMaximized


To the end of the code?

It may or may not work?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,539
Messages
5,572,786
Members
412,484
Latest member
deezina07
Top