Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
David[_6_] David[_6_] is offline
external usenet poster
 
Posts: 1
Default searching for multiple alternative string in MS Word?

I want to search for all occurrences of "which" in a document that are not
preceeded by prepositions. Is there any way to accurately do this with MS
Word's wildcard search?



Thanks


  #2   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default searching for multiple alternative string in MS Word?

On Sun, 24 Aug 2008 11:56:53 -0400, "David" wrote:

I want to search for all occurrences of "which" in a document that are not
preceeded by prepositions. Is there any way to accurately do this with MS
Word's wildcard search?



Thanks


Not with wildcards -- there is no wildcard for "preposition".

It would be possible to write a macro that finds each occurrence of "which" and
compares the preceding word to a list of all prepositions (such as that in
http://en.wikipedia.org/wiki/List_of..._prepositions).

What do you want to do after you find an occurrence? Also, does it make any
difference if there is punctuation between the occurrence and the preceding
word? Should the search be case-sensitive? Questions such as these should be
answered before starting to design the macro.


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
  #3   Report Post  
Posted to microsoft.public.word.newusers
levydav levydav is offline
external usenet poster
 
Posts: 1
Default searching for multiple alternative string in MS Word?

Yes, I want to include this function in a macro. I have written macros
that employ MS Word's wildcard search, but I don't know how to compare
part of a found string with a separate list of words. I would be
search for words without punctuation before "which"--e.g., "([A-z]@)
which"

Thanks for your help,



On Aug 24, 12:59*pm, Jay Freedman wrote:
On Sun, 24 Aug 2008 11:56:53 -0400, "David" wrote:
I want to search for all occurrences of "which" in a document thatare not
preceeded by prepositions. Is there any way to accurately do this with MS
Word's wildcard search?


Thanks


Not with wildcards -- there is no wildcard for "preposition".

It would be possible to write a macro that finds each occurrence of "which" and
compares the preceding word to a list of all prepositions (such as that inhttp://en.wikipedia.org/wiki/List_of_English_prepositions).

What do you want to do after you find an occurrence? Also, does it make any
difference if there is punctuation between the occurrence and the preceding
word? Should the search be case-sensitive? Questions such as these should be
answered before starting to design the macro.

--
Regards,
Jay Freedman
Microsoft Word MVP * * * *FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

  #4   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default searching for multiple alternative string in MS Word?

This macro should do what you want. Notice that I've left it up to you to finish
constructing the list of prepositions that should be matched -- I don't know how
many of them you want to include. Notice also that the way the macro is written,
you can't use any of the two-word or three-word prepositions ("according to",
etc.).

See http://www.gmayor.com/installing_macro.htm if needed.

Sub PrepositionWhich()
Dim oRg As Range
Dim PrepList As String

PrepList = "|about|above|across|against|along|among|around|as |at"
PrepList = PrepList & _
"|before|behind|below|beneath|beside|between|beyon d|by|"
' Continue this kind of assignment until PrepList contains
' all the prepositions you want to look for.
' Each word must have a | character before and after it, no spaces.

Set oRg = Selection.Range
If Selection.Type wdSelectionIP Then oRg.Collapse wdCollapseEnd
oRg.End = ActiveDocument.Range.End

With oRg.Find
.ClearFormatting
.Text = "[A-Za-z]@ which"
.MatchWildcards = True
.Format = False
.Forward = True
.Wrap = wdFindStop

Do
.Execute
If InStr(PrepList, "|" & Trim(oRg.Words(1)) & "|") Then
oRg.Select
Exit Sub
Else
oRg.Collapse wdCollapseEnd
End If
Loop Until Not .Found

MsgBox "No more occurrences."
End With
End Sub


On Mon, 25 Aug 2008 11:27:28 -0700 (PDT), levydav wrote:

Yes, I want to include this function in a macro. I have written macros
that employ MS Word's wildcard search, but I don't know how to compare
part of a found string with a separate list of words. I would be
search for words without punctuation before "which"--e.g., "([A-z]@)
which"

Thanks for your help,



On Aug 24, 12:59*pm, Jay Freedman wrote:
On Sun, 24 Aug 2008 11:56:53 -0400, "David" wrote:
I want to search for all occurrences of "which" in a document thatare not
preceeded by prepositions. Is there any way to accurately do this with MS
Word's wildcard search?


Thanks


Not with wildcards -- there is no wildcard for "preposition".

It would be possible to write a macro that finds each occurrence of "which" and
compares the preceding word to a list of all prepositions (such as that in
http://en.wikipedia.org/wiki/List_of..._prepositions).

What do you want to do after you find an occurrence? Also, does it make any
difference if there is punctuation between the occurrence and the preceding
word? Should the search be case-sensitive? Questions such as these should be
answered before starting to design the macro.


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
searching for a word in multiple files gfmc Microsoft Word Help 9 September 16th 08 10:06 PM
String Searching a Check box in Word... [email protected] Microsoft Word Help 1 April 7th 08 06:17 AM
searching multiple documents for a word(s) Bruce New Users 3 July 11th 06 07:57 PM
Searching multiple word documents dmrosy Microsoft Word Help 2 February 28th 06 05:30 PM
Searching Multiple Word Docs S McGill Microsoft Word Help 1 March 18th 05 08:10 PM


All times are GMT +1. The time now is 07:39 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"