Solved

Searching text in Word documents

Posted on 1999-01-23
4
149 Views
Last Modified: 2010-05-03
HELP, HELP in using VB5 Enterprise Edition.
Is there a way to include a function key in VB that will pull up the Win 95/98 Find dialog within your VB application to search for certain text in a "Word" document.  This would be the same as the F-3 key works in Outlook 97/98.

Thanks for you anticipated help.

Andre
0
Comment
Question by:abanks
  • 2
4 Comments
 

Author Comment

by:abanks
Comment Utility
Edited text of question
0
 

Expert Comment

by:israelw
Comment Utility
Dear abanks!

Why Do You Need To Run The Find Of Win95/98?

If You Want I Can Give You The Correct Code To Do This Within Your Vb code to find in a word document or set of word documents the certain text you want.

please response.

thank you.
israelw.
0
 

Author Comment

by:abanks
Comment Utility
Hi israelw,
Thanks for the response.  I would like to do this the best way possible within my App.  I would definitely like to see the Correct Code To Do This Within my Vb code. Once the app is running, I would like to be able to have the option to find text in a single word document or a set of word documents for the certain text I want.
Thanks
0
 
LVL 2

Accepted Solution

by:
FlorisMK earned 200 total points
Comment Utility
Good code would look somewhat like this

Giving your app F3 functionality:

- Create a search form (frmSearch);
- Set KeyPreview to True for your main form;
- Add the following code to the KeyDown event of your main form:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  frmSearch.Show vbModal
End Sub

- Add the following code to the search form:

Private Sub cmdSearch_Click()

  Dim wd As Word.Application
  Dim doc As Word.Document
  Dim f As Word.Find

  Dim sDocuments() As String

  Set wd = New Word.Application

  ' Execute the following code in a loop with
  ' each document you want searched; I'm assuming
  ' you can have a string array containing
  ' the name and path of the document

  ' Code to Redim Preserve the sDocuments array
  ' and fill it with the documents should go here

  For i = 0 To UBound(sDocuments)

    Set doc = wd.Documents.Open(sDocuments(i))
    Set f = doc.Range.Find

    With f

      ' Set the search string and search
      .Text = Me.txtSearchString.Text
      .Execute

      If .Found Then
        ' Select the text that was found
        .Parent.Select
        ' Show, bring to front, maximize Word
        wd.Visible = True
        wd.Activate
        wd.Windowstate = vbMaximized
      Else
        ' Or report that nothing was found in the current doc
        MsgBox "The text wasn't found in " & sDocuments(i)
      End if

    End With

  Next i

End Sub
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

10 Experts available now in Live!

Get 1:1 Help Now