# vb6 WebBrowser control



## booknet (Sep 14, 2004)

I use the following Code to find string in A HTMl in WebBrowser control, but 
if HTML support Frame then I get the error (run-time error "438"). any idea 
how to fix this error.
Thanks,
Harry


```
Public myfindFirst As Boolean
      Public oRange

Private Sub cmdFind_Click()
    Dim sSearch As String
    If myfindFirst Then
        Set oRange = WebBrowser1.Document.body.createTextRange
        sSearch = txtFind.Text
        If oRange.FindText(sSearch) Then
          oRange.Select
          oRange.scrollIntoView
          cmdFind.Caption = "Find Next"

          myfindFirst = False
        Else
         MsgBox ("Search string " & txtFind.Text & " not found.")
        End If
    Else
        Call oRange.Move("character")
        sSearch = txtFind.Text
        If oRange.FindText(sSearch) Then
            oRange.Select
            oRange.scrollIntoView
        Else
            MsgBox ("Finished searching Document for string " & 
txtFind.Text)
            cmdFind.Caption = "Find"
            myfindFirst = True
            Exit Sub
        End If
    End If

End Sub
```


----------



## Mosaic1 (Aug 17, 2001)

If you are working with frames there is no document.body

To test for the presence of frames:

```
Private Sub Command3_Click()
Set frames = WebBrowser1.Document.getElementsByTagName("frame")
  
If frames.length > 0 Then 'If there are frames
 For Each Frame In frames
   List1.AddItem Frame.LocationURL
 Next
End If
End Sub
```
This example will get you the url for each frame and add them to a list box.

Otherwise execute the other code.


----------



## Mosaic1 (Aug 17, 2001)

Here's something else to play with. This will put the html code of all frames for the currently loaded WebBrowser Document into a text box. You can use a variable or whatever.


```
Private Sub Command4_Click()
Dim Cont As Object
Dim sBody As String, k As Integer

For k = 0 To WebBrowser1.Document.frames.length - 1 

Set Cont = WebBrowser1.Document.frames(k).Document
sBody = Cont.body.innerHTML ' or use innerTEXT  if you prefer.
Text1.Text = Text1.Text & "NEXT" & vbCrLf & sBody & vbCrLf & vbCrLf & vbCrLf 
Next
End Sub
```


----------



## booknet (Sep 14, 2004)

yes, but how can I use these code to find A special text in webbrowser document (support Frame)?


----------



## Mosaic1 (Aug 17, 2001)

See if you can work with this instead. I haven't tried to find a string inside a frame. Search one frame at a time.


```
Dim range As Object
Dim k as Integer
  
  For k = 0 To WebBrowser1.Document.frames.length - 1

   Set range = WebBrowser1.Document.frames(k).Document.body.createTextRange


Add Search code.

Next
```


----------



## Mosaic1 (Aug 17, 2001)

Or you could set something up to search only selected frames.


----------

