Seaching a Word Document from Excel Part ii

V

VFXer

I have gottern some great help from Helmut Weber, MVP WordVBA on this subject
but have run into another problem. At the end I will put what I'm trying to
do.
When I try to search the word documents I have found that doing a search
using the following code cause a problem with the varible rDcm due to the
fact that the words I am search for are in a textbox in the word document and
to make manners worst there is a border going around the outside of the
docuemnts (they are certificates).

Sub Test455()

Dim col As Integer, row As Integer, s_counter As Integer

Dim sPth As String
Dim sNam As String
Dim oWrd As Object

col = 1
row = 2
s_counter = 1

sPth = "C:\Test Folder\"

Set oWrd = CreateObject("Word.Application")

oWrd.Visible = True
Sheets("Sheet3").Select
sNam = Dir(sPth & "*.doc")
While sNam <> ""
Range("C1").Value = s_counter
oWrd.Documents.Open sPth & sNam
Dim rDcm As Object
Set rDcm = oWrd.ActiveDocument.Range
Debug.Print rDcm
With rDcm.Find
.ClearFormatting
.Text = Range("E3").Value
While .Execute
rDcm.Select
Range("A" & row).Value = sNam
row = row + 1
Wend
End With
s_counter = s_counter + 1
oWrd.ActiveDocument.Close

sNam = Dir
Wend
oWrd.Quit
Set oWrd = Nothing
End Sub

Besdies this same, which Helmut provided I have tried to use the Built-in
Dialog Box functions such as wdDialogEditFind but these seem to have another
problem where I can't get it return a value based on the fact that it found
the word.

What I am trying to do is to create a list of file names of Word Documents
(certificates) that have been issues that have certain words in them. These
words will come from a list on a Excel Spreadsheet. Ideally I would like
tocreate something similar to the Search for words or pharse in Windows
Search menu item. The sample code above will do the search but as I said it
seems to ahve a problem with the fact that there is this border around a
textbox and the only results returned are something that looks like a small
"r"
Sorry for the length of this posting and thanks in advance for any help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top