PDA

View Full Version : Excel Macro - click after login to a website



karthiktel88
02-11-2012, 01:26 PM
Here is my code. I am new to excel macro. I need the following stuffs to do,

1. Goto google.com and click Sign-In(use this the link).
2. input credentials through macro and login.
3. Now you would be navigated to google.com. if you note thoroughly, you will see your "username" in the page.
4. Now i need to open Google News.
5. Remember, after navigating to Google News page, I STILL WANT TO SEE MY USERNAME IN THE GOOGLE NEWS PAGE.

my code works till login of gmail, and navigated to google news, BUT I AM GETTING LOG-OUT. MY USERNAME IS NOT VISIBLE IN GOOGLE NEWS PAGE.

PLEASE HELP. because of some error, i removing the links from the code and above description

Public Sub LaunchGamil(username As String)
Const strURL_c As String = "get the link by clicking Sign-in in google page" (DON'T USE GMAIL.COM, USE THE LINK WHICH YOU GOT THROUGH SIGN-IN LINK THORUGH GOOGLE.COM)
' the link will look like AccountdotGoogledotCom)
Const strURL1_c As String = "google news link"

Dim objIE As SHDocVw.InternetExplorer
Dim objIE1 As SHDocVw.InternetExplorer
Dim ieDoc1 As MSHTML.HTMLDocument

Dim tbxPwdFld As MSHTML.HTMLInputElement
Dim tbxUsrFld As MSHTML.HTMLInputElement
Dim btnSubmit As MSHTML.HTMLInputElement

On Error GoTo Err_Hnd
'Create Internet Explorer Object
Set objIE = New SHDocVw.InternetExplorer
Set objIE1 = New SHDocVw.InternetExplorer
'Navigate the URL
objIE.Navigate strURL_c
'Wait for page to load
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
'Get document object
Set ieDoc1 = objIE.Document
'Get username/password fields and submit button.
Set tbxPwdFld = ieDoc1.all.Item("Passwd")
Set tbxUsrFld = ieDoc1.all.Item("Email")
Set btnSubmit = ieDoc1.all.Item("signIn")
'Fill Fields
tbxUsrFld.Value = "username at gmail dot com"
tbxPwdFld.Value = "password"
'Click submit
btnSubmit.Click
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
While objIE.Busy
DoEvents 'wait until IE is done loading page.
Wend

objIE1.Navigate strURL1_c
Do Until objIE1.ReadyState = READYSTATE_COMPLETE: Loop

While objIE1.Busy
DoEvents 'wait until IE is done loading page.
Wend

Err_Hnd: '(Fail gracefully)
objIE.Visible = True
End Sub