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 / January 2006

Tip: Looking for answers? Try searching our database.

Find Error?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George Lee - 13 Jan 2006 18:28 GMT
When using VBA code to find "U.S." (for example), the Find range returns four
words with the first three being as expected ("U", ".", "S").

However, the last word may contain not only the final period but also the
next character in the document if the next one is a space or another
puncuation mark such as ".)". The user interface version of the Find does not
do this.

Is the code version a bug or have I overlooked something?
Greg - 13 Jan 2006 18:45 GMT
George,

I don't see that using:

Sub Test()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
 .ClearFormatting
 .Text = "U.S."
 .Forward = True
 .Wrap = wdFindStop
 Do While .Execute
   MsgBox oRng.Text
 Loop
End With
End Sub

What is your code?
George Lee - 24 Jan 2006 15:01 GMT
Looks to be the same:

   With myRange.Find
       .ClearFormatting
       .Text = "U.S."
       .Forward = True
       .MatchWholeWord = False
       .MatchCase = True
   End With

However, the Find comes out with four words: "U", ".", "S", ".?"

> George,
>
[quoted text clipped - 15 lines]
>
> What is your code?
Tony Jollans - 24 Jan 2006 20:18 GMT
How are you determining what is and isn't a word?

--
Enjoy,
Tony

> When using VBA code to find "U.S." (for example), the Find range returns four
> words with the first three being as expected ("U", ".", "S").
[quoted text clipped - 5 lines]
>
> Is the code version a bug or have I overlooked something?
George Lee - 26 Jan 2006 15:40 GMT
I'm not determining what is or isn't a word. I'm using the
myFindRange.Words(x) from the Find results.

> How are you determining what is and isn't a word?
>
[quoted text clipped - 13 lines]
> >
> > Is the code version a bug or have I overlooked something?
Tony Jollans - 26 Jan 2006 15:58 GMT
Yes, when you use VBA - and you are getting what I would expect (although
not necessarily what I would like).

But what makes you say anything is different when using the UI?

Actually, I think I may know what you're not understanding. When a Range
intersects with a Word, the complete word (or what Word considers the
complete word) is returned from any request for the word. The Found
Selection contains only four characters (U.S.) but the fourth 'word' is only
a partial word (the period from period-space) and the whole word is what you
get for word(4).

--
Enjoy,
Tony

> I'm not determining what is or isn't a word. I'm using the
> myFindRange.Words(x) from the Find results.
[quoted text clipped - 16 lines]
> > >
> > > Is the code version a bug or have I overlooked something?
 
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.