Solved

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

Posted on 2001-08-21
11
289 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
Access Object Property from VBA Module in Excel 2010 2 31
VB 6 error 5 in windows 10 but not in XP 7 56
Sub or Function is not defined 6 30
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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