Get more than one getElementsByTagName in loop?

Posted on 2005-03-31
Medium Priority
Last Modified: 2012-06-27
How do you obtain more than one TAG when recursing a document? What I am asking is how whould I extract a TABLE following the "A" link below? In other words, once I find a href link....move next extract the table following it so I can print both the link AND the first TABLE that follows after it!

Dim alink As HTMLLinkElement
Dim table As HTMLLinkElement
  For Each alink In WebBrowser1.Document.getElementsByTagName("A")
' just need to figure out how to get the table below the LINK!

debug.print alink
Question by:ohmeohmy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 28

Expert Comment

ID: 13676351

Author Comment

ID: 13677028
That sample wasn't any help.

How can I just check for a match in a loop to the elements? Like this:

Dim alink As HTMLLinkElement
Dim bfound as Boolean

  For Each alink In WebBrowser1.ALL

'Check if alink is a "A" tag then grab its text
' set a boolean to true if "A" has been found then
'next loop grab the "TABLE" text and set boolean = false and continue looking
'for the next "A" link


How difficult is it to make this work?

LVL 28

Accepted Solution

AzraSound earned 1000 total points
ID: 13680989
Well you were asking about recursing a document, and that is exactly what that sample does.  Now that your question is more clear, we can proceed.  The only way to really do this is iterate over all elements in order, and flagging when you find your anchor element and then searching for your table.  Example:

Dim eleAny      As HTMLObjectElement
Dim doc         As HTMLDocument
Dim blnFound    As Boolean
Dim i           As Integer

Set doc = WebBrowser1.Document

For i = 0 To doc.All.length - 1
    Set eleAny = doc.All(i)
    If TypeName(eleAny) = "HTMLAnchorElement" Then
        blnFound = True
        Do Until blnFound = False Or i = doc.All.length
            i = i + 1
            Set eleAny = doc.All(i)
            If TypeName(eleAny) = "HTMLTable" Then
                'found the next table - process here
                blnFound = False
            End If
    End If

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question