Results 1 to 3 of 3

Thread: Excel macro need to know how many internet objects to navigate different screens

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    2

    Excel macro need to know how many internet objects to navigate different screens

    I very new to excel macro. please help me. also suggest me very good material to learn vba concepts.

    See the below code,

    1. Macro should open this link "https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.co.in/" and enter account details.
    2. Navigated to google page. Now need to click Google maps link and enter London and click search.

    vb Code:
    1. Public Sub LaunchGamil(username As String)
    2.     Const strURL_c As String = "https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.co.in/"
    3.     Const URLmaps As String = "http://maps.google.co.in/maps?hl=en&tab=wl"
    4.     Dim objIE As SHDocVw.InternetExplorer
    5.     Dim objIE1 As SHDocVw.InternetExplorer
    6.     Dim ieDoc1 As MSHTML.HTMLDocument
    7.     Dim ieDoc2 As MSHTML.HTMLDocument
    8.     Dim tbxPwdFld As MSHTML.HTMLInputElement
    9.     Dim tbxUsrFld As MSHTML.HTMLInputElement
    10.     Dim btnSubmit As MSHTML.HTMLInputElement
    11.    
    12.     On Error GoTo Err_Hnd
    13.     'Create Internet Explorer Object
    14.     Set objIE = New SHDocVw.InternetExplorer
    15.     'Navigate the URL
    16.     objIE.Navigate strURL_c
    17.     'Wait for page to load
    18.     Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
    19.     'Get document object
    20.     Set ieDoc1 = objIE.Document
    21.     'Get username/password fields and submit button.
    22.     Set tbxPwdFld = ieDoc1.all.Item("Passwd")
    23.     Set tbxUsrFld = ieDoc1.all.Item("Email")
    24.     Set btnSubmit = ieDoc1.all.Item("signIn")
    25.     'Fill Fields
    26.     tbxUsrFld.Value = username
    27.     tbxPwdFld.Value = password
    28.     'Click submit
    29.     btnSubmit.Click
    30.     'Wait for transistion page to load
    31.     Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
    32.     'Wait for main page to load
    33.     'Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
    34.     While ieDoc1.Busy
    35.     DoEvents  'wait until IE is done loading page.
    36.     Wend
    37.     Set objIE1 = New SHDocVw.InternetExplorer
    38.     objIE1.Navigate URLmaps
    39.     Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
    40.    
    41. Err_Hnd: '(Fail gracefully)
    42.     objIE.Visible = True
    43. End Sub
    Last edited by Hack; Feb 11th, 2012 at 08:30 AM. Reason: Added Highlight Tags

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel macro need to know how many internet objects to navigate different screens

    how far does the code work?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    2

    Re: Excel macro need to know how many internet objects to navigate different screens

    Quote Originally Posted by westconn1 View Post
    how far does the code work?
    Here is my code. I am new to excel macro. I need the following stuffs to do,

    1. Open this(https://accounts.google.com/ServiceL....google.co.in/) link.
    2. input credentials through macro and login.
    3. Now you would be navigated to google.co.in. if you note thoroughly, you will see your "username" in the page.
    4. Now i need to open Google News. link is "http://news.google.co.in/nwshp?hl=en&tab=wn"
    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.

    Public Sub LaunchGamil(username As String)
    Const strURL_c As String = "https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.co.in/"
    Const strURL1_c As String = "http://news.google.co.in/nwshp?hl=en&tab=wn"

    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 = "[email protected]"
    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
    'objIE.Document.Links(0).target = "http://news.google.co.in/nwshp?hl=en&tab=wn"
    'objIE.Document.Links(0).Click
    While objIE1.Busy
    DoEvents 'wait until IE is done loading page.
    Wend

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


    With IEapp
    .Visible = True
    .Navigate URL1
    End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width