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
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