#1
|
||||
|
||||
Help with a logical code, end of paragraph lines
Hello Pro's,
I'll try my darnest to explain what I need, since it's hard for me to explain without and image, and I don't know how to enclose an image without granting access to my PC. It's a corporate thing. My issue: Long paragraphs, that overflows to the next line due to margins, how do I do a Find and Replace with situations where the end of line has an open parentheses, such as: Here below is 2 examples: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies (the So I want to:Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies (as
If it sees at the end of all sentences, an open parenthese with a Word, I want to add a non-breaking space = ^s so it will be glued to the following word so a sentence will NOT end with an open parentheses at the end of a line. So in these above cases: (the^spurus lectus) or (as^spurus lectus). Is that doable without touching all open braket with a word? I've been searching. My logic is thinking go to end of sentence and find the sentences that ends with (the or (as. Any insights would be sooooooooooooooo appreciated Cendrinne |
#2
|
||||
|
||||
Why not simply do it for all cases? For example, using a wildcard Find/Replace:
Find = (\(*>)^32 Replace = \1^s That way, regardless of any subsequent edits, you'll still get the desired outcome.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Yeah, that could work
Hello, Macropod,
The reason I was trying to avoid doing that, is because, having a whole document justified, makes spaces between words more spaced out. So to equilibrate the space vs letters, at times you don't want to do it everywhere in a paragraph. That is why I was wondering how to make it happen. I've looked at the Keyboard shortcuts: If I manually see at the end of the line, an open bracket with a word:
I don't think there's a way to program it to do that on it's own right? Cendrinne |
#4
|
||||
|
||||
This appears to work but I would need to see a big data set to be confident in it
Code:
Sub NoBreaksForTheWicked() Dim aRng As Range, iLine1 As Integer, iLine2 As Integer Set aRng = ActiveDocument.Range With aRng.Find .Text = "(\(<*) " .Replacement.Text = "\1^l" .Forward = True .MatchWildcards = True .Wrap = wdFindStop Do While .Execute iLine1 = aRng.Information(wdFirstCharacterLineNumber) aRng.Collapse Direction:=wdCollapseEnd iLine2 = aRng.Words(1).Information(wdFirstCharacterLineNumber) If iLine2 <> iLine1 Then aRng.MoveStart Unit:=wdCharacter, Count:=-1 aRng.Text = Chr(160) End If aRng.Collapse Direction:=wdCollapseEnd Loop End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
In Word 2013 & later, the non-breaking space (Character 160) has a variable width. Hence doing as I suggested will have no effect on the justification.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
||||
|
||||
It's all good :)
Quote:
The only thing I can say, is that what I was exactly looking for, Guessed was able to gather what I needed in is script. But it's not a contest, everyone of us, each put our thinking cap on, and we find a solution for the greatest good. This is a fantastic forum to exchange and learn. Thank you both of you (Guessed and macropod). I bow my hands to you both Cendrinne |
#7
|
||||
|
||||
I've done many test, and I say you should be confidant!!!!
Quote:
So YES you can be confidant. Thank you both of you, Guessed, and Macropod. You are both Great Mind Thinkers and Helpers. I thank you from the bottom of my heart Cendrinne |
#8
|
||||
|
||||
I've added other stuff to fix paragraph endings. On a 11 pages of paragraphs, it took 5 min. Is there anyway, to speed it up? Why is it taking so long?
Code:
Application.ScreenUpdating = False TST_End_of_Sentence_ 'suggested by Guessed Options.DefaultHighlightColorIndex = wdBrightGreen Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Highlight = True With Selection.Find .Forward = True .Wrap = wdFindStop .Format = True .MatchCase = True .MatchWildcards = True .Text = "(\(*>)^32" .Replacement.Text = "\1^s" 'suggested by Macropod .Execute Replace:=wdReplaceAll .Text = "(*>)^32(A-Z)" .Replacement.Text = "\1^s\2" .Execute Replace:=wdReplaceAll Options.DefaultHighlightColorIndex = wdYellow .Text = "(«)^32(<*)" '« .Replacement.Text = "\1^s\2" .Execute Replace:=wdReplaceAll .Text = "(>)^32(»)" '» .Replacement.Text = "\1^s\2" .Execute Replace:=wdReplaceAll .Text = "([%$])" '$% .Replacement.Text = "^s\1" .Execute Replace:=wdReplaceAll Options.DefaultHighlightColorIndex = wdTurquoise .Text = "([0-9]>)^32(millio[ns]@)" '0-9 millions .Replacement.Text = "\1^s\2" .Execute Replace:=wdReplaceAll .Text = "(rie>)^32([A-Z0-9])" 'serie 0-9 / categorie A-Z .Replacement.Text = "\1^s\2" .Execute Replace:=wdReplaceAll .Text = "([0-9]{4})-([0-9])" .Replacement.Text = "\1^~\2" .Execute Replace:=wdReplaceAll .Text = "([0-9]>) (<[adfjmnos])" 'Months .Replacement.Text = "\1^s\2" .Execute Replace:=wdReplaceAll End With Selection.Find.Execute Replace:=wdReplaceAll 'Reset Find and Replace Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = True .MatchCase = True .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll Application.ScreenUpdating = True |
#9
|
||||
|
||||
I don't know what 'TST_End_of_Sentence_' is about, but it seems to suggest you're running some sort of loop. Your code is also slow because of its heavy use of Selection.
With the Find/Replace operation I suggested, there'd be no looping through the content. All you'd use is: Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "([\(«]*>)^32" .Replacement.Text = "\1^s" .Forward = True .Format = False .Wrap = wdFindContinue .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End With Application.ScreenUpdating = True End Sub .Text = "(*>)^32(A-Z)" .Replacement.Text = "\1^s\2" would replace an ordinary space before any upper-case letter with a non-breaking space. Why would you do that? Similarly, .Text = "([%$])" .Replacement.Text = "^s\1" would insert a non-breaking space before % or $, even if there's already a space there, with the potential of ending up with both a space (which may or not be a non-breaking space) followed by non-breaking space.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
||||
|
||||
On a given paragraph, this script below didn't work......
Hello, Andrew,
I don't want to leave you with the impression, it worked all the time, cause in one case, it didn't. Didn't even flintch. So I want to let the readers here read it's not a 100% working script in those circumstances. Besides, does it exist and 100% full proof script? Or it's normal, it might not work all the time? I guess it depends if one variable is different than the test I've done previously. Quote:
I rather have a backup plan, than just one. Especially when time is an issue. Regardless, I love then help I get from this forum. I learn so much from people here Until next time. Cendrinne |
Tags |
help end of sentence, long paragraphs |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to change the line spacing between just 2 lines within a paragraph | Swarup | Word | 4 | 06-26-2019 02:32 PM |
How to get rid of horizontal lines after each paragraph? | Nisus | Word | 10 | 10-08-2018 01:15 PM |
double spaced within paragraph 2 blank lines between paragraphs | BigOldArt | Word | 1 | 08-24-2017 09:08 AM |
Lines refuse to merge into one paragraph (Word 2010) | Chris24 | Word | 2 | 01-22-2017 03:00 PM |
Keep Paragraph Lines Together Issue | SQLUSA | Word | 2 | 06-23-2012 05:00 PM |