Link to home
Start Free TrialLog in
Avatar of Robert Berke
Robert BerkeFlag for United States of America

asked on

Can MS Word 2010 Automatically remove Extra Space between Words?

MS Word grammar checker often says " Extra Space between Words:".  I always click "Change" and continue with the grammar checker.

In the last 5 years this great feature has caught and fixed about 5000 extra spaces, but it is a little annoying.

Does anybody know of trick to make MS Word automatically eliminate these spaces?  I sometimes use find and replace  "  " to " " but I would prefer that word just automatically make the correction.

rberke
SOLUTION
Avatar of DrTribos
DrTribos
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Berke

ASKER

The Autocorrect "From" textbox ignores leading and trailing spaces and does not accept wildcards, so that will not work.

The following macro seems to work, but I won't know for sure until I have used it for a few weeks.

I will post back and let you folks know how successful it was.

Bob

' In Word 2010 the F7 spell checker will frequently ask the user  if double space should be replace a single space.
'
' if this is annoying, you can make replacement be automatic by using this macro.   Customize the ribbon and use the "keyboard shortcuts" to assign the macro to Ctrl Shift F7.
'
    If Options.CheckGrammarWithSpelling = True Then
   
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "([ ])[ ]{1,}"
            .Replacement.Text = "\1"
            .Forward = True
            .Wrap = wdFindStop
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
            .MatchWildcards = False
            .Wrap = wdFindAsk
        End With

        ActiveDocument.CheckGrammar
    Else
        ActiveDocument.CheckSpelling
    End If

End Sub
Glad you have progress 😊
The macro was working well, but I made a small improvement.  This is the final version.

Sub Macro328()
' see experts-exchange question 28693441 from rberke

' In Word 2010 the F7 spell checker will FREQUENTLY ask the user if double space should be replaced by a single space.  I always respond Yes.
'
' I found this to be annoying, so I created this macro. I customized the ribbon and used the "keyboard shortcuts" to assign the macro to Ctrl Shift F7.
'
' Now, whenever I want to spell check, I use control shift F instead of F7, and the annoying message never comes up.
'
'
    If Options.CheckGrammarWithSpelling = True Then
   
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "([ ])[ ]{1,}"
            .Replacement.Text = "\1"
            .Forward = True
            .Wrap = wdFindContinue  ' This causes the entire document to be processed, not just the selected text.
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
            .MatchWildcards = False
            .Wrap = wdFindAsk       ' Return to "standard" behavior. Future find and replaces will ask if the entire document should be processed.
        End With
        ActiveDocument.CheckGrammar
    Else
        ActiveDocument.CheckSpelling
    End If
    MsgBox "The spelling and grammer check is complete."
End Sub