Neither ....nor thru macros

D

Designingsally

We are aware of neither .... nor set of words. If neither is used then nor
shd be used in the same sentence. Is it possible for macros to check this set
of words.

I tired with find and replace it didnt make sense.

I want the macros to find neither in a sentence. If neither exists then the
sentence must have nor. If nor exists in the same sentecne. Then, macros can
ignore. if neither exists and then nor does, i want the sentence must be
highlighted swith some msg say hello.

Can someone help me thru this?
 
P

Pesach Shelnitz

Hi Sally,

You already have several macros that use the same approach that you can use
in this case. Your macro should search in a loop for the word "neither". When
a search string is found, the range of the object on which Find.Execute was
called demarcates the search string found (the word "neither" in this case).
Your macro can then use the Instr function to ascertain whether " nor " is
found in the first (and only) sentence associated with that range.

Sub CheckForNor()
Dim findText1 As String
Dim findText2 As String
Dim commText As String
Dim myRange As Range
Dim pos As Integer

findText1 = "neither"
findText2 = "nor"
commText = "This sentence needs the word nor."
Set myRange = ActiveDocument.Range
With myRange.Find
.Wrap = wdFindStop
.MatchCase = False
.MatchWholeWord = True
Do While .Execute(findText:=findText1)
pos = InStr(1, myRange.Sentences(1), _
findText2, vbTextCompare)
If pos = 0 Then
ActiveDocument.Comments.Add _
Range:=myRange, _
Text:=commText
End If
myRange.Collapse Direction:=wdCollapseEnd
Loop
End With
Set myRange = Nothing
End Sub

By the way, the Word grammar checker detects and marks this error.
 
Top