Solved

HTML object library/ WebBrowser object

Posted on 2001-06-14
4
276 Views
Last Modified: 2012-06-21
I'm writing a function to scan through an HTML document object, and find an element based on the arguments being passed in.

Public Function GetHTMLElement(htmlDocument as HTMLDocument,  sElementName as String, Optional sElementType as String)

Dim oElement as HTMLhtmlElement
Dim i as Integer

If sElementType <> "" then
For Each oElement in htmlDocument.getElementsByTagName
???
Next oElement
End If

For i = 1 To htmlDocument.Frames.length
     ? = GetHTMLelement(htmlDocument.Frames(i).Document, "string", "string2")
next i

End function


This is all I have so far.  I'm interested in returning a collection of elements that match arg2 and arg3.  How do I populate this function with each element that matches the criteria?  Thanks for any commets/suggestions.
0
Comment
Question by:vt45
[X]
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
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6190889
try this:

On Error Resume Next

Dim oCollection As New Collection

For Each oElement In htmlDocument
   If Ucase$(oElement.name) = UCase$(sElementName) Then
      If UCase$(oElement.type) = UCase$(sElementType) Then
         oCollection.Add oElement
      End If
   End If
Next
0
 

Author Comment

by:vt45
ID: 6192583
Azra-

That works for one document, but if a particular webpage contains x frames, that means x document objects.  I want this function to keep calling itself until it has looped through all subframes and at the same time populating the collection the function is defined as.

Public Function GetHTMLElement(htmlDocument as HTMLDocument,  sElementName as String, Optional sElementType
as String) as Collection

Dim oElement as HTMLhtmlElement
Dim i as Integer

If sElementType <> "" then
For Each oElement in htmlDocument.getElementsByTagName
???
Next oElement
End If

For i = 1 To htmlDocument.Frames.length
    ? Set GetHTMLelement = GetHTMLelement(htmlDocument.Frames(i).Document, "string", "string2") 'i get a type mismatch here
next i

End function
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6193027
try:
GetHTMLElement(htmlDocument.Frames.Item(i).Document, "string", "string2")
0
 
LVL 9

Accepted Solution

by:
kprestage earned 100 total points
ID: 6193636
Try this...


Public Static Function GetHTMLElements(htmlDocument As Object, Optional sElementTagName As String, Optional sElementAttribute As String, Optional sElementName As String, Optional NewCall As Boolean = True) As Collection
Dim oElement As HTMLHtmlElement
Dim i As Integer
Dim o As Object
Static x As Collection

If NewCall Then Set x = New Collection
Set GetHTMLElements = New Collection

If sElementTagName <> "" Then
    If sElementAttribute <> "" Then
        For Each oElement In htmlDocument.getElementsByTagName(sElementTagName)
            If UCase(oElement.Attributes(sElementAttribute)) = UCase(sElementName) Then
                x.Add oElement
            End If
        Next oElement
    Else
        For Each oElement In htmlDocument.getElementsByTagName(sElementTagName)
            x.Add oElement
        Next oElement
    End If
Else
    For Each oElement In htmlDocument.All
        x.Add oElement
    Next oElement
End If

If htmlDocument.frames.length > 0 Then
    For i = 0 To htmlDocument.frames.length - 1
        Set o = htmlDocument.frames(i).document
        GetHTMLElements o, sElementTagName, sElementAttribute, sElementName, False
    Next i
End If
Set GetHTMLElements = x

End Function

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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