PDA

View Full Version : [SOLVED:] Macro to remove leading spaces AND retain formatting



lkpederson
02-13-2015, 07:15 AM
All,
I have documents which occasionally have leading spaces between outline levels (set through Styles) and text. I have found macros which will delete these leading spaces but they all corrupt the Style for that paragraph. For some reason, the text will end up being formatted in the Style for the next paragraph.

And the dog ate my homework i.e. the code I was playing with got deleted. I've tried:

1. Trim() which didn't work.

2. Setting a paragraph range, looking at the first character, if it's a blank, then using Mid() to remove the space.

3. Range.Find
.Text = ([ ])([A-Z]*>)(^13)
.Replacement.Text = "\2\3"
.Style = original style
.Execute Replace:=wdReplaceAll

Suggestions?

TIA,
Lise

gmayor
02-14-2015, 03:33 AM
Modify the paragraph styles themselves to provide the spacing bvetween paragraphs
To remove leading spaces from the start of paragraphs



Dim oPara As Paragraph
Dim orng As Range
For Each oPara In ActiveDocument.Paragraphs
Set orng = oPara.Range
orng.Collapse 1
orng.MoveEndWhile Chr(32)
orng.Delete
Next oPara