?
Solved

Searching text in Word documents

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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
Course of the Month9 days, 21 hours left to enroll

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