#1
|
|||
|
|||
Put last word of line at the new line if the length of the word is x
Hi, I am new in vba and I need to create macro that checks end word of the line and if the length of the word is less than x the word goes to new line. Thanks for all answers.
|
#2
|
||||
|
||||
Please define what you mean by 'line'. Are these lines within a paragraph, or separate paragraphs? Also, when moving a word, this will undoubtedly affect the next line. What do you want to do about that?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
all lines in whole documents...the word should goes to the next line right before words in that line
|
#4
|
||||
|
||||
You haven't answered the questions I asked.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
line hmm row in dokument ?
this is line 1 sdasldnasklndask this is line 2 |
#6
|
||||
|
||||
Do you not understand the difference between a line within a paragraph and a line that is a paragraph?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
No, I dont.
|
#8
|
||||
|
||||
Paragraphs are terminated by paragraph breaks, which appear as ¶ symbols at the end of each paragraph when you toggled Word's formatting display 'on'. Manual line breaks will appear as ↵ at the end of each line.
So: Quote:
But: Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
So the answer would be lines within a paragraph
|
#10
|
||||
|
||||
Which of the two versions I posted?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas
porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est.¶ |
#12
|
||||
|
||||
Try:
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[A-Za-z]{1,7}>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found If .End = ActiveDocument.Range.End Then Exit Sub If .Words.Last.Next.Information(wdVerticalPositionRelativeToPage) > _ .Information(wdVerticalPositionRelativeToPage) Then .InsertBefore Chr(11) .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
in "If .Words.Last.Next.Information(wdVerticalPositionRel ativeToPage) > _" that "_" means ? thx
|
#14
|
||||
|
||||
The _ is a line continuation character.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
OK, I am not quite sure which part of code check the length of the last word of the line and where shoud I put my x parameter...
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
macro to add brackets to each line and add single quotes to each word in the line | bracketandquotes | Word VBA | 17 | 02-16-2015 03:51 PM |
Word not 'rounding' letters up to word in next line (parents and orphans) | Asa | Word | 4 | 09-13-2014 06:47 PM |
Program to read Email subject line word by word | john23# | Outlook | 1 | 02-14-2014 10:21 PM |
Can you prevent an empty line from appearing in the first line of a page? | New Daddy | Word | 10 | 11-18-2013 07:01 AM |
Outlook 2010 Web Access Subject line length | Emerogork | Outlook | 4 | 06-08-2011 05:50 PM |