Solved

Searching text in Word documents

Posted on 1999-01-23
4
153 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

790 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