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.
 

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

Top