Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Problems with Range Search

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Malik Al-Amin - 21 Dec 2004 21:47 GMT
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
Word Heretic - 21 Dec 2004 23:20 GMT
G'day "Malik Al-Amin" <malamin2004@yahoo.com>,

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:

>Hi All,
>
[quoted text clipped - 70 lines]
>  Next
>End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.