
Remove spaces at end of paragraphs
Hi Frederik,
I think this has to do with the paragraph not changing in the selection, add
some .select statements and see what happens. Apart from that Word doesn't
seem to like to change the end of the paragraph and looses track ;-)
This code seems to do the trick:
Btw, one other thing, in this case probably unrelated but better to be save
then sorry, don't name your objectvariables the same as objects in Word,
oParagraph instead of Paragraph should save you trouble later on.
--------------------------------------------------
Dim oParagraph As Paragraph
Dim oRange As Range
Dim oRangePara As Range
Set oParagraph = Selection.Paragraphs(1)
Set oRange = Selection.Range
Do Until oParagraph.Range.InRange(oRange.Paragraphs.Last.Range)
Set oRangePara = oParagraph.Range
oRangePara.MoveEnd unit:=wdCharacter, Count:=-1
oRangePara.Text = RTrim(oRangePara.Text)
Set oParagraph = oParagraph.Next
Loop
Set oRange = Nothing
Set oRangePara = Nothing
Set oParagraph = Nothing
--------------------------------------------------
Hope this helps,
regards,
Astrid
So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/
Quote:
> Hi all,
> I wanted to create a macro that removes all the extra spaces at the end of
each paragraph in my
Quote:
> current selection. This is what I tried:
> For Each Paragraph In Selection.Paragraphs
> Paragraph.Range.Text = RTrim(Paragraph.Range.Text)
> Next
> But this resulted in Word going into a never-ending loop, so I had to
"ctrl+break" to stop it from
Quote:
> running. What is wrong with the code?
> Thanks in advance,
> Frederik