Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Searching A Word Document (A2K SR1)

    I have just been requested to develop a skills database that review / search company wide skills. No problem here. One twist, however, it that they want the database to be able to search personnel resumes stored as Word documents for key words.

    In a nutshell, Is it possible to link to a resume created in Word and then search through all of the text in the Resume to find all text that match a keyword input by the user?
    Regards,

    Gary
    (It's been a while!)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching A Word Document (A2K SR1)

    If you want to know which documents contain a certain keyword, you can use the Application.FileSearch object. To use it fully, you must set a reference to the Microsoft Office 9.0 Object Library (in Tools | References... in the Visual Basic Editor.) Example:

    Sub FindKeyword()
    Dim i As Long
    With Application.FileSearch
    .NewSearch
    .FileType = msoFileTypeWordDocuments
    ' Substitute appropriate path
    .LookIn = "F:Resumes"
    .SearchSubFolders = True
    ' I assumed that the user enters the keyword in a text box
    .TextOrProperty = Me.txtKeyword
    .Execute
    For i = 1 To .FoundFiles.Count
    ' Code to process file goes here
    MsgBox .FoundFiles(i)
    Next i
    End With
    End Sub

    If you want to find all instances of a keyword in a document, you need to start Word and open the document using Automation from Access. See <!profile=WendellB>WendellB<!/profile>'s website for a short tutorial on Automation with useful links. Post back if you need specific help.

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Searching A Word Document (A2K SR1)

    Thanks Hans.

    This will give me a great starting point. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards,

    Gary
    (It's been a while!)

  4. #4
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Searching A Word Document (A2K SR1)

    WOW Hans, This works great. Thanks again. <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>
    Regards,

    Gary
    (It's been a while!)

  5. #5
    New Lounger
    Join Date
    Feb 2001
    Location
    Sacramento, California, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Searching A Word Document (A2K SR1)

    This is great Hans! I can really use this. I have been trying to modify the code supplied to save the results, without success. I would like to either save in a table, or to print out a list, instead of individual msgbox's.

    I am not very good at code yet, but trying all the time. I guess I need something to replace the line " ' Code to process file goes here ", but I haven't been able to figure out what to do with it.

    Any help would be GREATLY appreciated!

  6. #6
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Searching A Word Document (A2K SR1)

    Which results are you trying to save? Each filename where the matches occur? Number of hits in a file? Or other.

    I plan to save the name of each file such that the user can print out either the names of the files with matching data or provide a listbox where they can select which files to print. Is this what you are looking for?
    Regards,

    Gary
    (It's been a while!)

  7. #7
    New Lounger
    Join Date
    Feb 2001
    Location
    Sacramento, California, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Searching A Word Document (A2K SR1)

    I am trying to print/save each filepath & filename that it finds. I just tried Han's suggestion with the "Selection.TypeText .FoundFiles(i)" & "Selection.TypeParagraph", but I get a Variable not define error on the "Selection" statement. I just noticed that this thread was for A2K, and we are still using A97; but the msgbox search was working fine. Is the "Selection.Type" code not available in my old version?

  8. #8
    New Lounger
    Join Date
    Feb 2001
    Location
    Sacramento, California, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Searching A Word Document (A2K SR1)

    Thanks, Hans! I just received both yours and Gary's replies and was not able to use the "Selection.type" statement...probably because I am still using A97 ? The msgbox was working fine.

    Any suggestions?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching A Word Document (A2K SR1)

    I'm sorry! My fault - I was thinking in Word VBA instead of Access VBA. Let's say you have a table tblDocuments with a text field DocName. You could use this instead of the MsgBox line:

    CurrentDb.Execute "INSERT INTO tblDocuments (DocName) VALUES (" & Chr(34) & .FoundFiles(i) & Chr(34) & ")"

    This line will insert a record into tblDocuments.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching A Word Document (A2K SR1)

    Sorry, this answer is irrelevant - it contains Word VBA instead of Access VBA - brain lapse!

    If you want to create a list of the found documents, you could replace the MsgBox line by

    Selection.TypeText .FoundFiles(i)
    Selection.TypeParagraph

    This assumes that you have a (blank) document open when you call the code.

  11. #11
    New Lounger
    Join Date
    Feb 2001
    Location
    Sacramento, California, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Searching A Word Document (A2K SR1)

    Hans, THANKS! Worked wonderfully. All of you moderators are just too good!

  12. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Searching A Word Document (A2K SR1)

    Hi Hans

    Great code!

    What would I have to change to restrict the look in all documents like:

    "F:ResumesInv*.doc" (lookin all document names prefixed with Inv)

    or

    "F:Resumes*cnf*.doc" (lookin all documents names that contain cnf)

    Thanks, John

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching A Word Document (A2K SR1)

    John,

    The FileSearch object has several properties in which you specify the files to search:
    <UL><LI>FileName: a string that may include wildcards * and ?, for example "Inv*.doc" or "*cnf*.doc".
    <LI>FileType: use this if you want to search ALL files of a certain type, e.g. msoFileTypeWordDocuments or msoFileTypesOfficeDocuments. Specify either FileName or FileType, not both.
    <LI>LookIn: the path to search, for example "F:Resumes".
    <LI>SearchSubFolders: a Boolean specifying whether all subfolders of the LookIn path should be searched too.[/list]So in your first example:

    With Application.FileSearch
    .NewSearch
    .LookIn = "F:Resumes"
    .FileName = "Inv*.doc"
    .Execute
    ...
    End With

  14. #14
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Searching A Word Document (A2K SR1)

    Thanks

  15. #15
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Searching A Word Document (A2K SR1)

    Hans,

    One last twist. After searching the documents for the key words, is there a way to make the words standout such as highlighting or bold. Of course the original document would have to remain unchanged. Thanks for all of your help.
    Regards,

    Gary
    (It's been a while!)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •