Login to Google Account using VBA
Here is a simple code that will login to Google accounts with the provided user-name and password.
The program requires references to the following:
1 Microsoft Internet Controls
2. Microsoft HTML Object Library
Microsoft HTML Object Library- VBA Reference
Microsoft Internet Controls - VBA Reference
The Internet control is used to browse the webpage and the HTML Objects are used to identify the username and password textboxes and submit the text using the control button.
Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = "https://www.google.com/accounts/Login"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
HTMLDoc.all.Email.Value = "sample@vbadud.com"
HTMLDoc.all.passwd.Value = "*****"
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub
See Also : http://vbadud.blogspot.com/2008/05/google-search-using-vba.html
Saturday, August 08, 2009
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.
Good morning. I am a very amatuer coded but have navigated through this script well so far. I am having issues identifying the "object" or whatever I'm suppose to reference to enter a password on https://intex.com/main/login.php. The issue in the code that I'm having is at the HTMLDoc.all.Email.Value = and the HTMLDoc.all.Password.Value = lines of code. Could you look at the source of my target URL and let me know what I need to change? Thanks so much for your help.
ReplyDeleteI had the same problem.
ReplyDeleteCopy the procedure code to a Public Sub in a module rename it subTEST. I use modTEST as a name for the module.
Substitute this:
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
Debug.Print oHTML_Element.Name
Next
In the immediate window run subTEST.
The names of the fields should print. Try them all till you find the one that works.
On this line code breaks:
ReplyDeleteDebug.Assert Err = 0
It's an unnecessary line, that duplicates the one above it, but for contrary condition. I recommend erasing it.
Hi,
ReplyDeleteThis tutorial is awesome; this really helped me a lot.
I’ve a question: How do I click on a specified link (Hyperlink) to go to next page or do next task?
The way it is given for submit button.
Thanks
Hey everyone I fond this code and used it. Thus far it works like a charm to connect to Google. Also I agree if you were to take Debug.Assert Err = 0 part out the code works perfect and you no longer get the annoying error.
ReplyDeleteNow I am trying the same code to connect to another webpage and for some reason its not inputting the my usename or my password in the required field. This is what I mean to say
'Now wait untill internet explorer is ready
Loop Until oBrowser.readyState = ReadyState_Complete
Set HTMLDoc = oBrowser.Document
HTMLDoc.all.UserName.Value = " "
HTMLDoc.all.Password.Value =" "
I am leaving the fields blank. But everytime I run the code I get to the desired webpage but it doesnt put in my info as requested in the code.
Can some one please help me :)
Hi All,
ReplyDeleteIm ahving the same issue. I know this is an old post so i dont expect much of an answer.
*******************
Set HTMLDoc = oBrowser.Document
HTMLDoc.all.UserName.Value = " "
HTMLDoc.all.Password.Value =" "
********************
for some reason the HTMLDoc is comming back as "Nothing"???
therefore its not inputting my used name or password.
any assistance would be greatfull
I'd like to thank you, even at Oct/2012 this post keeps helping people!
ReplyDeleteDid anyone have any security issues after using this code? Any stolen password or account?
ReplyDeleteIs there a way to get those "username" and "password" names from table or form. I mean not the values of "username" and "password" but the names of those fields in HTML.
ReplyDeleteWhat I want to do is to use one universal script to log to many different sites. The only difference will be the names of "username" and "password" fields in HTML of the site. So I want to write something like this:
HTMLDoc.all.FORM!CONTROL.Value = " "
hey, i tried the code and i get this error:
ReplyDelete"The object invoked has disconnected from its clients "
At line:
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Can some1 help me?
i need an extra step to be added to this code is :
ReplyDeletesearch a text / string on the web page which is the proof that web page is loaded completely and update the excel cell with Good
sir,
ReplyDeletei have three credentials to enter into wesite they are
login
password and
client code
please help me to login automatically
function decodeHTML(value)
ReplyDelete{
var element = document.createElement('div');
element.innerHTML = element.textContent = value;
value = element.innerText || element.textContent;
delete element;
return value;
The above code is written in sourcecode can we use element collection, element name I could not use this
WHERE CAN I GET THE PROGRMS FOR THESE...
ReplyDelete1 Microsoft Internet Controls
2. Microsoft HTML Object Librar
I would like to copy the data from web using by following link
ReplyDeletewww.tcmb.gov.tr/WPS/wcm/connect/EN/TCMP+EN/Main+Menu/Statistics/Exchange+Rates/Indicative+Exchange+Rates#