Problems with Range Search

M

Malik Al-Amin

Hi All,

I'm trying to perform a simple search. I know that the text that I'm
seaching for exist but it's not being found. I physically searched the
document and found the text but it appears to have an extra space due to
line formating. I've tried to remove this space with the trim functions but
I'm still unable to successfully search. Hears an example:
1.1. UCR332.2 SA or PA has entitlement to run this report.
(The above line contains an extra space do to the line.) Not all lines that
will be searched has this problem. My question is how do I only grab the
text and perform my search? Again the trim function wont work. I'm
searching against the range.text. I was under the impression that this only
returned the text not any additional formatting. Here's my code.


Dim docTraceTree As Document, docUseCase As Document
Dim para As Paragraph
Dim rngUseCase As Range, rngTraceTree As Range
Dim intBkmCount As Integer
Dim bkm As Bookmark
Dim strCaseBookMark As String
Dim J As Integer
Dim strMyTrace As String
Set docTraceTree = Documents.Open(FileName:="C:\Documents and
Settings\A021871\Desktop\TraceTree.doc", Visible:=True)
Set docUseCase = Documents.Open(FileName:="C:\Documents and
Settings\A021871\Desktop\UseCase.doc", Visible:=True)
Dim strLeftOfColon As String
Dim strRightOfColon As String
Dim intLength As Integer
Dim intColonLocation As Integer
Dim strSearch As String
Set rngTraceTree = docTraceTree.Content

docUseCase.SaveAs "C:\CaseTraceMerge.doc"

For J = 1 To docUseCase.Bookmarks.Count
Set bkm = docUseCase.Bookmarks(1)
Set rngUseCase = docUseCase.Bookmarks(J).Range
rngUseCase.TextRetrievalMode.IncludeHiddenText = False
rngUseCase.Underline = False
rngUseCase.Bold = False

strMyPara = Trim(rngUseCase.Text)

intLength= Len(strMyPara)
strLeftOfColon = Left(strMyPara, (InStr(1, strMyPara, " ") - 1)) & ":"
intColonLocation = InStr(1, strMyPara, " ") - 1

strRightOfColon = (Mid(strMyPara, intColonLocation + 1))
strRightOfColon = RTrim(strRightOfColon)
strSearch = strLeftOfColon & strRightOfColon

rngTraceTree.Find.Text = strSearch
rngTraceTree.Find.MatchAllWordForms = False

rngTraceTree.Find.Execute

If rngTraceTree.Find.Found Then


Do
Set rngTraceTree = rngTraceTree.Next(wdParagraph, 1)
If Not rngTraceTree.Text Like "UCR*" Then
With rngUseCase
.Collapse direction:=wdCollapseEnd
.InsertParagraphAfter
.Text = rngTraceTree.Text
End With
End If

Loop Until rngTraceTree.Text Like "UCR*"
End If



Next
End Sub
 
W

Word Heretic

G'day "Malik Al-Amin" <[email protected]>,

the instr looking for a colon is looking for the first space mate:
stick a colon in between these rabbit ears (")

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Malik Al-Amin reckoned:
 

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