Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 38

Thread: Click URL links with VBA

  1. #1
    Join Date
    22nd August 2012
    Posts
    26

    Click URL links with VBA

    In the past few days I was working on a VBA project which needs automation to the website. However, this one is harder than I thought and I donít know how and where to start it.

    This is the website I am trying to login automatically (https://defben.retirementpartner.com...te/default.asp). This is built by a vendor and they used a lot of frames, JavaScript and VBScript. As you can see on the website and what I want is to click that Login button. I've tried to loop through the tags (seems like this link doesnít have a tag), grab the frames (I found total 6 frames but couldnít find where the linkage have this Login button), and use F12 to view the source code just to see if there is a way I can make my mouse to click that button but in vain.

    Can anyone help me to write an Excel VBA code so when the user click a button, it will click the Login on the 1st page and then the very first click here button on the 2nd page?

    Thanks for the time,

    Ian

    P.S. If you see a picture when you open the website, just click any of them and it will direct you to the page with that Login button.

    This is also posted here (http://www.mrexcel.com/forum/excel-q...lications.html).

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    14th July 2004
    Posts
    10,539

    Re: Click URL links with VBA

    Ian

    I tried to find a way to do this yesterday(?) but came to a dead end.

    There's seems to be frames within frames within frames.

    I'll give it another go with a more brute force method.
    Boo!

  3. #3
    Join Date
    14th July 2004
    Posts
    10,539

    Re: Click URL links with VBA

    This bypasses the frames and opens the document contained in the menu frame on it's own.
    VB:
    Sub test() 
        Dim IE As InternetExplorer 
        Dim doc As HTMLDocument 
        Dim frm As HTMLFrameElement 
        Dim frms As HTMLElementCollection 
        Dim strSQL As String 
         
        strSQL = "https://defben.retirementpartner.com/membersite/globalresources/menu/Menu.asp" 
         
        Set IE = CreateObject("InternetExplorer.Application") 
        With IE 
            .Visible = True 
            .Navigate strSQL 
             
            Do Until .ReadyState = 4: DoEvents: Loop 
                Set doc = IE.Document 
                 
                doc.getElementsByTagName("A")(0).Click 
                 
                 
                 
            End With 
        End Sub 
    
    
    Boo!

  4. #4
    Join Date
    22nd August 2012
    Posts
    26

    Re: Click URL links with VBA

    Thanks, Norie. You are everywhere helping people. Very nice of you. Yes, you did help me yesterday and I am still searching around to see if there is an answer.

    I know they built many frames and I couldn't really follow their codes. Please let me know if you need anything so we can tackle this down.

    Thanks again and have great day.

    Ian

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    22nd August 2012
    Posts
    26

    Re: Click URL links with VBA

    Thank you, Norie. I just tried your code and it seems we are getting something.

    A quick note here. I tried the way by getting the URL with Login words only page (the Menu.asp) before, and this actually won't let me login properly. Instead it will ask me to update the password and nothing will happen. I am thinking to retrieve all the tag names and inner texts to see if there is a way to click that Login word. Do you think you can find a way to use getElementsByTagName and find all the tags? I tried getElementsByTagName("*") and loop but I got an error. Maybe I didn't declare the syntax correctly. Please let me know if you can help me.

    Thanks,

    Ian

    Excel Video Tutorials / Excel Dashboards Reports


  6. #6
    Join Date
    14th July 2004
    Posts
    10,539

    Re: Click URL links with VBA

    Ian

    GetElementsbByTagName/ID/Classname was the sort of thing I was trying yesterday.

    I kind of guessed going straight to the page wouldn't be ideal, it's just hit or miss if it is.

    I'll have another look at things tomorrow.
    Boo!

  7. #7
    Join Date
    12th August 2012
    Posts
    37

    Re: Click URL links with VBA

    From the very first page, which company are you wanting to log in for?
    WebsterDeMonstration&Associates
    SunTrust
    USEppersonUnderwritingCompany
    GwinnettCounty
    Great-WestLife&Annuity
    CanadaLifeAssuranceCo
    Gwrs

    Excel Video Tutorials / Excel Dashboards Reports


  8. #8
    Join Date
    22nd August 2012
    Posts
    26

    Re: Click URL links with VBA

    Hi sjeter,

    This page will be only displayed when you first visit the site. You can click any of them just to pass it. Then the next page is what I am working on.

    Thanks,

    Ian

    Excel Video Tutorials / Excel Dashboards Reports


  9. #9
    Join Date
    22nd August 2012
    Posts
    26

    Re: Click URL links with VBA

    Hi Norie,

    I modified the code as below. But how do I find all the tags? Is there any wildcard I can use to replace "A"? I tried "*" but it doesn't work. Not sure what went wrong.

    And from trying the code below, I didn't see the link that I can click on the "Login" word.

    VB:
    Option Explicit 
     
     
    Sub test() 
        Dim IE As InternetExplorer 
        Dim doc As HTMLDocument 
        Dim frm As HTMLFrameElement 
        Dim frms As HTMLElementCollection 
        Dim strSQL As String 
        Dim i As Integer, j As Integer 
         
        strSQL = "https://defben.retirementpartner.com/membersite/default.asp" 
         
        Set IE = CreateObject("InternetExplorer.Application") 
        With IE 
            .Visible = True 
            .Navigate strSQL 
             
            On Error Resume Next 
            Do Until .ReadyState = 4: DoEvents: Loop 
                Set doc = IE.Document.frames 
                For i = 0 To doc.Length - 1 
                    For j = 0 To 100 ' Not sure how to find the last tag name
                        Debug.Print doc(i).getElementsByTagName("A")(j) ' Not sure if there is a wildcard to replace "A"
                    Next 
                Next 
            End With 
        End Sub 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


  10. #10
    Join Date
    14th July 2004
    Posts
    10,539

    Re: Click URL links with VBA

    Ian

    I've tried similar code and the main problem was that the frame with the link is within one of the frames on the main document.

    I've managed to get a reference to the right frame but I'm not referencing it 'properly'

    By 'properly' I mean in a way that allows you to access the link.
    Boo!

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Possible Answers

  1. Replies: 2
    Last Post: January 18th, 2011, 09:23
  2. Replies: 8
    Last Post: May 14th, 2010, 05:10
  3. Create Click-able Links to Worksheets
    By 2unesgrl in forum EXCEL HELP
    Replies: 4
    Last Post: September 13th, 2007, 13:16
  4. Replies: 4
    Last Post: March 6th, 2007, 00:45
  5. Replies: 2
    Last Post: August 19th, 2005, 21:59

Bookmarks

Posting Permissions

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