Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
537 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Posted by Andrew Gould on 03 June 2019
This video explains how to use VBA to enter Windows Security credentials when you connect to a website. You'll learn how to pass a username and password when you send an XML HTTP request. You'll also learn how to use the Windows Script Host Shell object to access the security dialog box and write a username and password using the SendKeys method.
See our full range of VBA training resources, or test your knowledge of VBA with one of our VBA skills assessment tests.
This video has the following accompanying files:
File name | Type | Description |
---|---|---|
Logging in to a Website with Windows Security.xlsm | Excel workbook with macros |
Click to download a zipped copy of the above files.
There are no exercises for this video.
You can increase the size of your video to make it fill the screen like this:
Play your video (the icons shown won't appear until you do), then click on the full screen icon which appears as shown above.
When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.
To improve the quality of a video, first click on the Settings icon:
Make sure yoiu're playing your video so that the icons shown above appear, then click on this gear icon.
Choose to change the video quality:
Click as above to change your video quality.
The higher the number you choose, the better will be your video quality (but the slower the connection speed):
Don't choose the HD option shown unless your connection speed is fast enough to support it!
Is your Wise Owl speaking too slowly (or too quickly)? You can also use the Settings menu above to change your playback speed.
From: | aaaakkik |
When: | 07 Jul 22 at 20:34 |
Hi,
I have an issue , we have a security keys for example:Zukey, in order to login to a website we need to press that manual it senses and then takes in the code . How can this be scrapped in the vba code.
Kindly help me
Thank you & regards,
Priyanka
From: | Andrew G |
When: | 08 Jul 22 at 06:56 |
Hi there! I'm sorry but I don't know the answer to that one.
From: | Chris10101 |
When: | 02 May 21 at 21:23 |
Hi,
This was a great traning and everything worked fine. The issue i have is after login i get redirected due to the type of login process. Normal login works fine. I can login and notice the url being redirected to outside source and redirected back to the customers nornal page for account use. Could you help me get loged in and get to my account after with this method, please?
From: | Andrew G |
When: | 03 May 21 at 06:55 |
Hi Chris,
It's quite difficult to offer help for systems that we don't have access to ourselves. Is there a specific thing that isn't working for you? What does your code look like?
From: | Pete |
When: | 13 Apr 20 at 13:16 |
Hi Andrew,
hope that you´re still fine!
I have perhaps, a small prob.
I want to login a specific Web SideTherefore I found your video and tried .
But .. I can not login
I can open the specific Web Site.
(After watching your Vidio and typed the Code in a Module)
The First error I got is at the point
Debug.Print...inner Text (see first Sub)
There is nothing shown in the "Direct Window"
I got the error : "Variable of Object or with ... not declared"
Trying the 2nd Sub I got the error at the Step
Do While IE.ReadyState.. READYSTATE_COMPLTE
I found out that I got the error Run Time Errore at the sequence Do While EReadyState (Runtime error 21470 231 79)
and at the sequenz "READYSTATECOMPLTE" it is shown = 4
What have I done?
So.. I tried to activate Net Framework. but I´m not allowed to do this (I´m not the administrator.. unfortunately)
What is the source Code of the Webside?
For User Name
form name ="pnForm"... id = "pnForm"
input name = "a1234..." width = "0" Title = "User name input" ... id = "Enter user name"
What do I see wenn Net Side is openend?
User Name then a field to type in the user name
Below
Password then a field to type in the password
and after this a button to sign in
I hope taht I could descripe my prob and will hope that you have an idea what´s goin wrong ?
Take Care !
Pete
From: | Andrew G |
When: | 14 Apr 20 at 10:14 |
Hi Pete, this video shows a different technique for logging into a website to the one you're describing. I think you need some of the techniques shown in an earlier video https://www.wiseowl.co.uk/vba-macros/videos/vba-scrape-websites/scraping-web-pages/
In that video you can see some examples of entering text into a form and clicking a button. I hope it helps!
From: | marklah |
When: | 21 Nov 19 at 19:56 |
Hi Andrew,
Thanks a lot for such very informative videos.
I have tried dozens of different websites but have not got the login pop-up window shown on the video . I even created an account on wise owl and also did not see the login window. Am i missing anything? Any website I should use to test that login code?
Thanks and looking forward to hearing from you.
From: | Andrew G |
When: | 22 Nov 19 at 09:01 |
Hi there, no don't worry, you haven't missed anything! Not many websites use Windows security to validate user credentials. The websites which do tend to be internal systems such as the one I used in this video which is Wise Owl's internal diary system. Here's a brief description of how to configure a website to use Windows authentication https://support.microsoft.com/en-gb/help/323176/how-to-implement-windows-authentication-and-authorization-in-asp-net
I hope that helps!
From: | marklah |
When: | 25 Nov 19 at 21:57 |
Many thanks Andrew. Actually i noticed later that it was my IE settings to have an auto login using my current credentials. When i change the setting to prompt for username then i started seeing that login security window on the intranet site :) . i a m still getting an error on Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy for a reason but its not a big matter though i believe it smth to do with my intranet site.
Thanks again and much respect !
From: | Andrew G |
When: | 26 Nov 19 at 08:42 |
That's great! Pleased to hear that you're making progress!
From: | Eric Zhang |
When: | 01 Sep 19 at 14:15 |
Hi, Andrew,
realy appreciated for your kind reply. after study your video i'm able to login the web by using IE mode, thanks again, i will need more study on this XML mode. i study some article about using Fiddler to analyze the setrequestheader and Cookie method.
thanks, have a good day.
From: | Andrew G |
When: | 02 Sep 19 at 07:26 |
You're very welcome, Eric. I hope you find a solution to your problem!
From: | Eric Zhang |
When: | 28 Aug 19 at 11:14 |
Realy appreciated for those video, is there any way to sign in a web by using XML method.
From: | Andrew G |
When: | 29 Aug 19 at 07:32 |
Hi Eric,
Yes, we do explain how to do that in the video, or did you mean something different?
From: | Eric Zhang |
When: | 29 Aug 19 at 08:06 |
Thanks for reply, i did see the video, the method is that VBA can pass username and password to the web. but faild. the reason is might username field is encode by base64, i guess. below are the HTML code.
after google it, i found someone said, it has to use a fake cookie or hijact the js script.
<input name="userName" type="text" id="userName" class="ebk3-inText" placeholder="User name" style="background-image: url("data:image/png;base64,iVBORw0"); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%; cursor: auto;">
From: | Andrew G |
When: | 29 Aug 19 at 11:44 |
Hi Eric,
The video is related to logging in using basic Windows security. From the code you've posted it looks as though you need to enter a username into an HTML element on the page. I answered a similar question on YouTube recently and include the code below to give you an idea of how to do this:
Sub TestLogin()
Dim ie As SHDocVw.InternetExplorerMedium
Dim doc As MSHTML.HTMLDocument
Dim LoginForm As MSHTML.HTMLFormElement
Dim UserNameInput As MSHTML.HTMLInputElement
Dim PasswordInput As MSHTML.HTMLInputElement
Set ie = New SHDocVw.InternetExplorer
ie.Visible = True
ie.navigate "https://www.marketingscents.com/index?page=login-new"
Do While ie.readyState <> READYSTATE_COMPLETE And ie.Busy
Loop
Set doc = ie.document
Set LoginForm = doc.getElementById("js-login-form")
Set UserNameInput = LoginForm.getElementsByClassName("form-control input-lg")(0)
Set PasswordInput = LoginForm.getElementsByClassName("form-control input-lg")(1)
UserNameInput.Value = "my user name"
PasswordInput.Value = "my password"
LoginForm.submit
End Sub
If the page involves javascript I believe that you need to use the browser rather than the XML approach, although I don't consider myself an expert in this at all! If you need to simulate cookies or obtain security tokens, this is somewhat more complicated.
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.