Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Searching text in Word documents

Posted on 1999-01-23
4
Medium Priority
?
158 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 400 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Suggested Courses

610 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