+ Reply to Thread
Results 1 to 6 of 6

click hyperlink from td in tr

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    57

    click hyperlink from td in tr

    Hello all

    I have the following code and I want to be able to click the hyperlink associated with the td of the webpage. How do I do this?

    Dim trCollection As Object
        Dim tdCollection As Object
    
        Dim tdObj As Object
        Dim trObj As Object
        Dim dd As Object
    
        'get everything in the dividends table using its id
        Set tbObj = ie.document.getElementById("Form0") 'all table elements including headers
    
    'get the four rows for the ONT stock (headings and data elements
        Set trCollection = tbObj.getElementsByTagName("tr")
    
    Dim i As Integer
     i = 1
    'get the eight data items for each row of the ONT stock e.g stock price date etc.
        For Each trObj In trCollection
    
        If i = 1 Then
    'print each data element one by one for each of the four rows
            Set tdCollection = trObj.getElementsByTagName("th")
            Else
              Set tdCollection = trObj.getElementsByTagName("td")
    
          End If
    
          i = i + 1
    
            For Each tdObj In tdCollection
    
                If tdObj.innerText = "13-14 " Then
                   ZT = 1
                End If
                
                If tdObj.innerText = "Assessments " And ZT = 1 Then
                    'I WANT TO CLICK THE HYPERLINK ASSOCIATION WITH THE ABOUT "ASSESSMENTS" REFERENCE                
                    
                End If
            Next
    
        Next
    Thanks.

    James

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: click hyperlink from td in tr

    Hello Jimbo77,

    The href property belongs to an Anchor object which supports the Click event. You will need to get the anchor object in the table cell (TD) from the innerHTML.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    03-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: click hyperlink from td in tr

    Thanks very much for replying Leith. How do I find the innerHTML?

  4. #4
    Registered User
    Join Date
    03-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: click hyperlink from td in tr

    Anyone?

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: click hyperlink from td in tr

    Hello James,

    The innerHTML is property of the TD object.
     
        innerHTML = TD.innerHTML
    This will return the HTML code associated with the table cell. This is where is gets tricky finding the object you need. If the Anchor object has an ID property then it is very easy. You can return the object directly...
        ' In this example we'll say the id property is "web_pic_100". DocObj refers to the variable referencing the Document Object in your code.
            Set Anchor = DocObj.getElementByID("web_pic_100")
            Anchor.Click
    If you don't have an ID then I will need to see the HTML code for the cell to help you further.

  6. #6
    Registered User
    Join Date
    03-31-2013
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: click hyperlink from td in tr

    For what it is worth I solved the problem with this bit of code

    Set AllHyperLinks = ie.document.getElementsByTagName("A")
                            For Each hyper_link In AllHyperLinks
        
                              
                                If InStr(1, tdObj.innerHTML, hyper_link.outerHTML, vbTextCompare) > 0 Or InStr(1, hyper_link.outerHTML, tdObj.innerHTML, vbTextCompare) > 0 Then
                                       
                                        hyper_link.Click
                                        Exit For
                                End If
                    Next

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to Click a Hyperlink on webpage
    By sugaprasad in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-04-2013, 10:10 AM
  2. click on Hyperlink with macro
    By PriyankaGurav in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-06-2013, 04:06 AM
  3. click hyperlink in listview
    By cnimes in forum Excel General
    Replies: 1
    Last Post: 11-07-2012, 10:19 AM
  4. Run Macro on Hyperlink click
    By karmaimages in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-24-2012, 03:15 PM
  5. Checking if last click was a Hyperlink
    By Reporter in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-19-2009, 05:51 AM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1