Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with replacing manual line breaks in a document 1

Status
Not open for further replies.

sonname

Programmer
May 18, 2001
115
US
I need a piece of code that will scan through a document and remove all manual line breaks i.e.<[lb]> hidden tokens in the document. Also, when the code finds these manual line breaks in the document, does it know at what number position it found them?
 



Hi,

Take a look at Get MS Word Copy/Paste-text to word wrap properly faq68-1449

Skip,

[glasses] [red][/red]
[tongue]
 
sonname - please stop posting this. This is the third time for the same thing.

1. Need help with macro that replaces line break and colors text (on May 10)


2. Replacing all hidden text markers code help (on May 14)


3. Need help with replacing manual line breaks in a document (on May 16)

You have not responded properly in the previous posts. What? Do you think if you just ignore what has been posted and ask again you will get the answer you want?

All your posts are the exact same question. You have had people try and answer for you. Please respond there. If the replies do not work for you, say so. Do not just make another post.

Skip, the FAQ procedures will not work, as the OP is asking about hyphenation, which are - contrary to what the OP seems to think - NOT manual line breaks.

Gerry
My paintings and sculpture
 
Oh, and sonname? I asked in one of the other posts.

Where are you getting <[lb]> from? I asked there, and ask again. This is not a Word thing. You did not bother to answer. It may help if you do.

Please do NOT just make another new thread.

Gerry
My paintings and sculpture
 
Sorry about the double posting. I am really stumped with this issue. I have tried just about everything that I can think of to get this to work. Fumei, your code for looping through words would have worked perfectly, the problem is that if there is a <[lb]> in the middle of a word, it doesn't see that word as one word only. The <[lb]> comes from when a user does a SHIFT + ENTER in word. It inserts a manual line break, it ends the current line and continues the text on the next line.
 
sonname

SHIFT-ENTER creates a manual line break. If this is all that is boggling you and creating all these postings, try this:

Sub KillLineBreaks()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^l"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

 
I hate repeating myself. One more time...

As WalkerEvans has posted, removing manual line breaks is very very easy. The macro recorder would show you. WalkerEvans's code shows you. It replaces ^l.

However, you are stating <[lb]>.

I asked once, twice...now three times, and I am not asking again.

Where is this <[lb]> coming from? It is NOT a Word thing. It is NOT a Word thing...and now the third time...it is NOT a Word thing.

A manual line break is ^l, not <[lb]>.

You are trying to tell us that you have users that get to the end of the page margin - from the other posts - on the word probably...
and manually type:

p
r
o
b
...and somehow know to use a manual line break..
SHIFT + ENTER
a
b
l
y

I don't believe it. If this is true, you have the most unusual users. Most people would type "probably". Yes hyphenation may break it into:

prob
ably

But you are stating the user manually made a line break into the word. A long word, I can believe. "Probably"? I doubt that very much.

I will say it again. If it is hyphenation then it is NOT a manual line break - ie. ^l.

And that still does not answer where the heck you are getting <[lb]>.

Gerry
My paintings and sculpture
 
I did some asking around and I guess Quark is what puts in those <[lb]> characters.
 
So here is what I did to remove them.

Selection.HomeKey Unit:=wdStory
With Selection.Find
Do While (.Execute(Findtext:="-<[lb]>", Forward:=True) = True) = True
Selection.Delete
Loop
End With

What I now need to do is highlight the word at the position where the -<[lb]> was found. I did write a post for finding a word at a given position. I have been looking at the Word object, but have not had success yet.
 
I did some asking around and I guess Quark is what puts in those <[lb]> characters.
Well....finally. Was that so hard?


Don't you think this may have been relevant? So your statement that the user did a SHIFT + ENTER (in Word) was not....um, correct?

The -<[lb]> is text. Text. Text. Notice in your code that worked the parameter Findtext:= "-<[lb]>"? Text. Not a manual line break. Text.

I did write a post for finding a word at a given position.
Yes, you did.

If I have a numbered position in a document, is there a way to get the word at that position and highlight it?
I posted an answer to that question.


"Yes."

Yes, there is a way to get a word at a numbered position. Could you state where/how you got this number? Does this have ANY relevance to this post on the NOT manual line break?

I think it does, as your first post wanted to remove the (not) manual line break, and highlight the word that did have it. But your code does not give you a number. It is possible to get that number, but you are not doing that. So...what number are you talking about?

Sigh. This has taken four separate threads. You don't answer questions. You ignore replies that don't work for you. MakeItSo posted some code for you...and you just left it, and started a new thread. This is not a good process to get our help.

I am very tempted to leave this hanging. Someone else may come along and help you. However, the following will do what I think you want.
Code:
With Selection.Find
   Do While (.Execute(Findtext:="-<[lb]>", _
          Forward:=True) = True) = True
      With Selection
         .Delete
         .Expand Unit:=wdWord
         .Range.HighlightColorIndex = wdYellow
         .Collapse Direction:=wdCollapseEnd
      End With
   Loop
End With
It deletes the text "-<[lb]>", expands to cover the word, and then (yellow) highlights the word, collapses to its end, then goes on to the next Findtext.

Please, with all due respect, go and read the FAQ on how to write good posts. These ones were not well done at all.

Gerry
My paintings and sculpture
 
Thanks, this works well. Sorry about the unclear posts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top