Check Double Spaces

S

Sahana

Hi I m trying to detect the presence of double space. I got the code
as well but the macros doesnt really highlight the double spaces
(using comments) at every instance. It just kinda highlights with some
blue highlight mark. Anyways I need some macros to detect double IF
WORDS ARE PRESENT BEFORE AND AFTER the DOUBLE space.

Example,

I have ten pots.

Macros should detect the double spaces.

If something like this is present like

ARTICLE

then macros should not detect the double spaces here.

Macros are

Sub Spacesemdash()
Dim oRng As Range
Selection.HomeKey Unit:=wdStory
With Selection.FInd
.ClearFormatting
.Wrap = wdFindStop
.Text = " "
Do While .Execute
Set oRng = Selection.Range
With oRng
.MoveEnd Unit:=wdCharacter, Count:=1
.MoveStart Unit:=wdCharacter, Count:=-1
'With .Characters
If .Last = "[a-z]" Or .First = "[a-z] " Then
ActiveDocument.comments.Add _
Range:=oRng, _
Text:="There should be no spaces before or
after an en dash."
End If
End With
End With
Loop
End With
End Sub


Pls tell me where modifications are to be done
 
P

Pesach Shelnitz

Hi Shalmali,

The grammar checker automatically adds wavy lines for extra spaces. This has
nothing to do with the macro.

The following macro finds all extra spaces between words and adds a comment.
If you want to find only double spaces, remove the comma after the '2'.

Sub FindExtraSpaces()
Dim myRange As Range

Set myRange = ActiveDocument.Range
With myRange.Find
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute("[A-Za-z][ ]{2,}[A-Za-z]")
ActiveDocument.Comments.Add _
Range:=myRange, _
Text:="Extra space between words."
myRange.Collapse Direction:=wdCollapseEnd
Loop
End With
Set myRange = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top