Solved

How to "find on this page" inside a MSBrowser control

Posted on 2001-08-21
11
293 Views
Last Modified: 2008-05-22
I am displaying a text page using a MSInternet Control (browser).
What code will allow me to search the page for the occurance of a string and scroll the page to that point?
0
Comment
Question by:rbend
[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
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6411225
hearing...
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 50 total points
ID: 6411277
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
 
LVL 14

Expert Comment

by:wsh2
ID: 6411720
<ping>
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6411796
Would SendKeys("^F")  (CTRL-F) do what you are after?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6411929
anthony_glenwright, nice and simple and works too!
It is matter of opinions, but to me, sendkeys is a "last resort".
Your comment has very good advantages: no create objects, don't waste resources, it's clever indeed.
Anyway, you need put others sendkeys to set text to search and push the search button.
Cheers
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6411966
I agree about the sendkeys :-)

Here's a more elegant way

wbrDisplay.ExecWB OLECMDID_SHOWFIND, OLECMDEXECOPT_PROMPTUSER
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6411969
Oops, my bad.  The webbrowser control does not support OLECMDID_SHOWFIND - ref:  http://support.microsoft.com/support/kb/articles/Q251/1/33.ASP
0
 

Author Comment

by:rbend
ID: 6413146
Richie:
I found the Microsoft HTML Object Library in the componants list and added it to the project but I still get "object required" on the line  
"Set ieDoc = web1.Document"
Do I have to add a module with something in it or what?
 
0
 

Author Comment

by:rbend
ID: 6413160
Richie:
I found the Microsoft HTML Object Library in the componants list and added it to the project but I still get "object required" on the line  
"Set ieDoc = web1.Document"
Do I have to add a module with something in it or what?
 
0
 

Author Comment

by:rbend
ID: 6413163
Sorry...found my error.
Great answer...
bb
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6413306
Thanks!
I would like to say that Anthony's solution was a valid one.
It is a pity that OLECMDID_SHOWFIND doesn't works. I like that approach more than mine!
Cheers
0

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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