Results 1 to 6 of 6
  1. #1
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83

    Clicking links in webpages


    I have been searching for an answer but I have come up short. I have this code below to take me to a webpage, but I cannot figure out how to click on the link i want. I have to go through this method because the link on the webpage exports the document to excel.

    Code:
    Public Sub launch_site()
    
        Dim IE As Object
    
        Set IE = CreateObject("InternetExplorer.application")
        
        IE.Visible = True
        IE.Navigate "WEBPAGE HERE"
        Do Until IE.ReadyState = 4
        Loop
        AppActivate "Internet Explorer", True
        SendKeys "USERNAME", True
        Do Until IE.ReadyState = 4
        Loop
        SendKeys "{TAB}", True
        SendKeys "PASSWORD", True
        Do Until IE.ReadyState = 4
        Loop
        SendKeys "~", True
        Do Until IE.ReadyState = 4
        Loop
        IE.Document.All("HYPERLINK HERE").Click
        
    
    End Sub

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if you're going to use the document.all() method, you have to reference the NAME attribute of the tag. the only way to find that string is in the page's source, via a browser. you can also use the getelementbyid() method, but obviously you have to use the ID attribute with that:
    Code:
    ie.document.getElementById("id").click
    if all else fails, you can also try using the LINKS collection and the index number of your link. you can get all the links with a simple iteration, or you can look through the page source from top to bottom and count on your fingers from 0 on. with this method, you would use:
    Code:
    ie.document.links(index).click
    Note, that you cannot use the [] bracket in VBA, as it is specifically for javascript.

    and if you didn't know, you can also open the browser and go directly to the file, if the browser is set to download files when the url is hardcoded. This is set by default in every browser today.

  3. #3
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    Thanks Adam, I will try this when Monday rolls around and get back to you. I thought I did grab the name when I viwed page source, but maybe I looked at the wrong string.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if you can't find it, you can list the captions of the links out in your I window, liks so:

    Code:
    dim link as object
    
    for each link in ie.document.links
       debug.print link.innertext
    next link
    ''innertext'' will return the link representation text that you see on the webpage itself

  5. #5
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    Adam,

    I actually found a great post by yourself on another forum "Navigate Internet Explorer using VBA" and realized it was a tab i was trying to click on. But i tried getelementbyID on google finance for practice and it worked so I have no doubt with some trial and error (and with your iteration statement below if all else fails), when work rolls around tomorrow I will find something that does the job. Thanks again.

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by dssrun View Post
    Adam,

    I actually found a great post by yourself on another forum "Navigate Internet Explorer using VBA" and realized it was a tab i was trying to click on. But i tried getelementbyID on google finance for practice and it worked so I have no doubt with some trial and error (and with your iteration statement below if all else fails), when work rolls around tomorrow I will find something that does the job. Thanks again.
    Good for you for figuring it out! At least it's doing some good for someone!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Print Report by clicking record
    By jamil_kwi in forum Reports
    Replies: 1
    Last Post: 10-05-2010, 08:23 AM
  2. Clicking on label opens up new record
    By swimmermx in forum Forms
    Replies: 2
    Last Post: 07-20-2010, 03:58 PM
  3. Can you set a combo box to open links?
    By Procom Webserve in forum Access
    Replies: 2
    Last Post: 12-07-2009, 03:11 AM
  4. Problems opening links from access
    By anguyen in forum Access
    Replies: 0
    Last Post: 09-22-2009, 06:43 AM
  5. Testing links
    By piflechien73 in forum Forms
    Replies: 0
    Last Post: 06-01-2009, 05:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums