|
|
|
|
|
|
|
|
Word
|
Eliminate Multiple Spaces
|
|
|
Ease of Use
|
Easy
|
|
Version tested with
|
2000
|
|
Submitted by:
|
lucas
|
|
Description:
|
Reduces excessive spaces between words to one space
|
|
Discussion:
|
You have imported text or pasted it into your document or for whatever reason, you have more than one space between a lot of the words. This routine will reduce those excessive spaces to one space.
|
|
Code:
|
instructions for use
|
Place this code In a standard module:
Option Explicit
Sub EliminateMultipleSpaces()
'If something goes wrong, go to the errorhandler
On Error Goto ERRORHANDLER
'Checks the document for excessive spaces between words
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'Here is where it is actually looking for spaces between words
.Text = " [ ]@([! ])"
'This line tells it to replace the excessive spaces with one space
.Replacement.Text = " \1"
.MatchWildcards = True
.Wrap = wdFindStop
.Format = False
.Forward = True
'execute the replace
.Execute Replace:=wdReplaceAll
End With
With .Find
'This time its looking for excessive spaces after a paragraph mark
.Text = "^p "
'What to replace it with
.Replacement.Text = "^p"
.MatchWildcards = False
.Wrap = wdFindStop
.Format = False
.Forward = True
'Execute the replace
.Execute Replace:=wdReplaceAll
End With
End With
ERRORHANDLER:
With Selection
.ExtendMode = False
.HomeKey Unit:=wdStory
End With
End Sub
|
|
How to use:
|
- Open the Visual Basic Editor by going to tools-Macro's-Visual Basic Editor or use Alt-F11
- On the toolbar of the Visual Basic Editor, go to insert - module
- In the module pane paste the code above.
- Close the Visual Basic Editor by clicking the X in the upper right corner or go to File-Close
|
|
Test the code:
|
- Type a sentence into your document and add extra spaces between the words.
- On the main menu go to tools-macro-macros.
- In the dialog window select EliminateMultipleSpaces and then click run.
- The excessive spaces will be reduced to one space.
|
|
Sample File:
|
EliminateMultipleSpaces.zip 9.66KB
|
|
Approved by MOS MASTER
|
|
This entry has been viewed 91 times.
|
|
|