Solved

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

Posted on 2001-08-21
11
287 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now