Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-08-21
11
Medium Priority
?
296 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 200 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
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…
Suggested Courses

719 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