strip leading/trailing spaces

W

wordproc

I frequently strip leading/trailing spaces from text using:

Ctrl+A
Align Center
Align Left

I recorded a macro of these same steps which reads:

Sub strip()
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End Sub

But when executed, all it does is Select All and stops, as if there are no
other commands, leaving the text selected.

Does anyone know how to accomplish these three steps in VBA?
 
W

wordproc

I obtained the answer from another forum and have posted it here for anyone
else who may need this bit of information:

Selection.WholeStory
Application.CommandBars("Formatting").Controls("Center").Execute
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft

Notice the difference between the "Center" command line and the
"wdAlignParagraphLeft" command line.
 
Top