Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2001-08-21
11
Medium Priority
?
297 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

885 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