View Single Post
  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Remove 2 Characters from the end of each line?

'Line' is a vague concept in Word as lines are totally dependent on text
flow and content. Are these 'lines' in fact paragraphs - terminated with a
paragraph mark ¶? In which case the following macro will both remove any
empty paragraphs and remove the last two characters (excluding the paragraph
mark) of each line

Sub Remove2Chars()
Dim oRng As Range
Dim i As Long
With ActiveDocument
For i = .Paragraphs.Count To 1 Step -1
Set oRng = .Paragraphs(i).Range
With oRng
.End = .End - 1
If .Text = "" Then .Delete
.Characters.Last.Delete
.Characters.Last.Delete
End With
Next i
End With
End Sub

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Jgrant wrote:
Alright, and how do I make it remove the last 2 characters? They are
usually a - and a space, but it is sometimes something else, so I need
it to remove the last 2 characters.
DeanH;432759 Wrote:
Firstly, try the quick and simple, select the text, click on the
Centre align
icon (Ctrl+E), then the Left align icon (Ctrl+L), this usually gets
rid of
any superfluous spaces and tabs from the start and end of paragraphs.
For multiple paragraphs you can use Find/Replace, using ^p^p for the
find
and ^p for the replace, this will get rid of two paragraph marks and
replace
with one.
See http://sbarnhill.mvps.org/WordFAQs/CleanWebText.htm for this and
other
tips, also see http://gregmaxey.mvps.org/Clean_Up_Text.htm for a
macro that
can help if you need to do this a lot.
--
Hope this helps
DeanH


"Jgrant" wrote:
-

Hi

I'm wondering if it's possible to record a macro, or code one, or if
there's some easy function that will remove two characters from the
end
of each line in Word. The lines are all different lengths.

Also, is there anyway to make Word remove blank lines? (No characters
or anything. Just like if you hit enter twice. There's that line with
nothing in it?)




--
Jgrant
-