Solved

Searching text in Word documents

Posted on 1999-01-23
4
155 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
[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
  • 2
4 Comments
 

Author Comment

by:abanks
ID: 1470341
Edited text of question
0
 

Expert Comment

by:israelw
ID: 1470342
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
ID: 1470343
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
ID: 1470344
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 …
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…

734 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