Solved

Webbrowser and find ...

Posted on 2002-03-20
8
212 Views
Last Modified: 2010-05-02
Hi!

I have a embedded Webbrowser and it's showing a HTML file. I have textbox and a OK Button in top of the HTML form. If i press the OK Button it should search for the text (which is in the textbox) and go to this "line". Is this possible?

Falke
0
Comment
Question by:Falke
  • 6
  • 2
8 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6883055
yes, it is possible.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6883093
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 6883097
if you don't want to spend a penny:

Well you need to set references to microsoft html object library.
I have added one textbox to type text to serach and a command button to do the search. Webbrowser control's
name is wb1.


Option Explicit

Private Sub Command1_Click()
Dim ieDoc As HTMLDocument
   Set ieDoc = wb1.Document
   With ieDoc
       Dim TxtRng As IHTMLTxtRange
       Set TxtRng = .body.createTextRange
       If TxtRng.findText(Text1.Text) = True Then
           TxtRng.Select
           TxtRng.ScrollIntoView True
       Else
           MsgBox "Text not found", vbInformation, App.EXEName
       End If
   End With
End Sub

Private Sub Form_Load()
wb1.navigate "www.experts-exchange.com"
End Sub


Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is wb1.Object) Then
   Command1.Enabled = True
Else
   Command1.Enabled = False
End If
End Sub

Hope it helps
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6884822
Here's one that is a bit of an upgrade on the one Ritchie posted (although I would guess that they are based on the same original sample)  -  :-)

This for if you want the full functionality (i.e. up/down, match case and full word only).

It needs:
-  A text box called txtFindTerm
-  A command button called cmdFind
-  two option buttons, optDown - "search down" and optUp - "search up" (in a frame)
-  Two check boxes, chkWholeWord - "Search whole word only" and chkCase - "Match case".

And there is a public variable called wbrDocument that is set to the document property of your webbrowser.

<general declarations>
Public wbrDocument As MSHTML.HTMLDocument
Private rngTextRange As IHTMLTxtRange

Private Sub cmdFind_Click()
  Dim intFlags As Integer
  Dim lngDirection As Long
 
  If Len(txtFindTerm.Text) > 0 Then
    If rngTextRange Is Nothing Then
      Set rngTextRange = wbrDocument.body.createTextRange
    End If
   
    With rngTextRange
      intFlags = 0
      If chkWholeWord.Value = vbChecked Then
        intFlags = intFlags + 2
      End If
      If chkCase.Value = vbChecked Then
        intFlags = intFlags + 4
      End If
     
      If optDown.Value = True Then
        lngDirection = 65535
        .moveStart "character", 1
        .moveEnd "character", 1
      Else
        lngDirection = -65535
        .moveStart "character", -1
        .moveEnd "character", -1
      End If
         
     
      If .FindText(txtFindTerm.Text, lngDirection, intFlags) = True Then
        .Select
        .scrollIntoView True
      Else
        MsgBox "Finished searching this page.", vbExclamation
      End If
     
    End With
  End If
 
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6885302
Anthony, to tell you the true, i figured it by myself.
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6887164
Must be a case of covergent evolution :-)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6887549
When i posted code, sure is mine otherwise post the link or at least, a mention to real author.
Sometimes, there are few ways to get things to work.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6903364
Thanks for "A" grade!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 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