Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Remove 2 Characters from the end of each line?
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?) |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Remove 2 Characters from the end of each line?
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 |
#3
|
|||
|
|||
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.
Quote:
|
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 - |
#5
|
|||
|
|||
That didn't work at all.
I have this sort of a thing: Victorian Hat Black - shop[4] - 650 - Victorian Hat White - shop[4] - 650 - Victorian Hat Green - shop[4] - 650 - Victorian Hat Beige - shop[4] - 650 - I want the last - removed, because it's pointless, but it is followed by a space. Quote:
|
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Remove 2 Characters from the end of each line?
As I indicated in my previous post, 'line' is a vague concept. The macro I
quoted removes the last two characters from each *paragraph*. Click the ¶ button (or CTRL+*) to display the hidden characters then see what the makeup of the line endings really is and what the line termination characters are. However if all the lines are similar in layout to the list you quoted, you can tackle it a different way Use Replace with the wildcard option set to replace (\] - [0-9]{3}) - with \1 -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Jgrant wrote: That didn't work at all. I have this sort of a thing: Victorian Hat Black - shop[4] - 650 - Victorian Hat White - shop[4] - 650 - Victorian Hat Green - shop[4] - 650 - Victorian Hat Beige - shop[4] - 650 - I want the last - removed, because it's pointless, but it is followed by a space. Graham Mayor;433843 Wrote: '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 - -- |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I remove squares and characters mixed in with text? | Microsoft Word Help | |||
cursor floating on line & characters not typing across line | Microsoft Word Help | |||
Remove single repeating characters | Microsoft Word Help | |||
Remove line of characters inserted by Word 2003 | Microsoft Word Help | |||
remove special characters | Microsoft Word Help |