Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word search in Word Documents 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
A user has asked if a word or phrase can be entered in an Access form which can then be searched for in a collection of linked (by path) Word Documents for there presence and then collation. Anyone done a word document word search from Access, can it be done. Thanks
 
Does anyone know how I move on from this macro done in word. Presumeably I can open a word document in Access and integrate the macro vb in some way. Somehow generating a variable to say the word searched for was found or not found, and then proceed with the next document. Any advice greatly appreciated. Thanks

Sub Macro1()

ActiveWindow.ActivePane.SmallScroll ToRight:=-1

End Sub

Sub Macro2()

Selection.Find.ClearFormatting
With Selection.Find
.Text = "DAVID BECKHAM"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Selection.Find.Execute

End Sub
 
No takers?
I have this so far, but it crashes saying object required??

If I can get this part to work, and some log as to whether the word was found I.m moving. In addition I don't need to see the document. Help!!
 
Sorry, forgot to paste code.

No takers?
I have this so far, but it crashes saying object required??

If I can get this part to work, and some log as to whether the word was found I.m moving. In addition I don't need to see the document. Help!!

Private Sub Command136_Click()
Dim LWordDoc As String
Dim oApp As Object

On Error GoTo Err_Command136_Click

'Path to the word document
LWordDoc = "c:\Logging\Test.doc"

If Dir(LWordDoc) = "" Then
MsgBox "The Transcription Document " & LWordDoc & " cannot be found?."

Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True

'Open the Document
oApp.Documents.Open Filename:=LWordDoc, ReadOnly:=True


Selection.Find.ClearFormatting
With Selection.Find
.Text = "and"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Selection.Find.Execute


End If

Exit_Command136_Click:
Exit Sub

Err_Command136_Click:
MsgBox Err.Description
Resume Exit_Command136_Click
End Sub
 
Ever had the feeling your talking to yourself? I solved the error, had not referenced the MS Word object library. Now how do I do it to open unseen, and log if that document had the word. Anyone? Thanks
 
To open unseen, you can simply remark this line:

oApp.Visible = True

An update query may be the easiest, unless you simply want a list. The result of Dir is the file name.

You may wish to consider file search if you have a powerful computer, it will take an SQL string.

Windows Desktop Search 3.01 (WDS 3.01)

More details are available from:
How Can I Find All the Files in a Directory Tree that Contain a Specific Word or Phrase?
Windows Desktop Search 3.0 Properties
 
Many thanks Remou. The desktop search looks very good, however I am trying to search a small number of word documents, in a known location, for a word or phase. I need to then compile a list of the documents having been found to include the word or phrase, within Access. Best regards
 
Here is a snippet from something similar that I did some time ago:

Code:
        Set doc = wd.Documents.Open _
            (FileName:=strDoc, ReadOnly:=True, AddToRecentFiles:=False)
        
            wd.Selection.Find.ClearFormatting
            With wd.Selection.Find
                .Text = "To:"
                .Forward = True
            End With
            wd.Selection.Find.Execute
            If wd.Selection.Find.Found Then
                wd.Selection.EndKey Unit:=wdLine, Extend:=wdExtend
                strWordData = wd.Selection.Range
                rsProc.AddNew
                rsProc!FileFullPath = strDoc
                rsProc!TextFromDoc = Left(strWordData, Len(strWordData) - 1)
                rsProc.Update
            End If
        
        doc.Close

It writes the file name and the found line to a table.


 
Hey Remou, thank you very much, I will have a play with that. Thanks again.
 
Having problems closing the document and the word application. I tried using this, but the next time I hid the button it complains the remote server being unavailable, presumeably as word instance still exists?

' doc.Close

ActiveDocument.Close wdDoNotSaveChanges
WD.Application.Quit
 
Many Thanks again, I'm on my way!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top