PDA

View Full Version : With *.find problem



debkev1010
06-17-2009, 08:05 AM
Hi, I have code that grabs the contents of a cell in a worksheet and searches for the contents in a word document. I'm using the Object.Find function. This code works most of the time (the field in the worksheet is colored "red" if not found in the text and "green" if found in the text); however, for the cases in which it doesn't work (field is colored red but the contents of the field are in the text), I can perform a Ctrl+F, insert the contents of the cell into the Find window, click on Find, and the contents are found in the text. Here are the bits of code:

dim cellstring as String
dim wdDoc as Object
dim wdRng as Object

set wdDoc = wdApp.Documents.Open('path & filename')
set wdRng = wdDoc.Content

wdRng.Find.ClearFormatting
wdRng.Find.Replacement.ClearFormatting

for i = 1 to 10
cellstring = cells(i,2)

With wdRng.Find
Do
.Text = trim(cellstring)
.Replacement.Text = ""
.
.
.Execute
if .found then
color cells green
exit do
else
color cells red
end if
loop while .found
end with
next

Thanks for your help,
Kevin

fumei
06-17-2009, 08:58 AM
And what are you asking exactly?

I take it you are using late-binding?