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:
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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
 
Upvote 0
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:
 
Upvote 0
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?
 
Upvote 0
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:
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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. :)
 
Upvote 0
This code is great! Anyone know how to make IE open in a maximized state? That would be most helpful to me.

Thanks
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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