Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Is word at end of the line

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jlhamann - 06 Jan 2008 07:22 GMT
When I seach for a word with the code:

   Selection.Find.ClearFormatting
   With Selection.Find
       .Text = " on"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute

Is there a way to determinine is the word is the last word on that line?  I
want to certain words to be moved to the next line if they are at the end of
a line.
Tony Jollans - 06 Jan 2008 09:37 GMT
There is nothing you can really do about end of line per se - it is not a
fixed position and depends on the printer.

If what you actually have is paragraph marks and/or manual line breaks
explicitly causing the line breaks I would strongly suggest you avoid the
practice and leave Word to flow the text to fit the page, but you could
search for them immediately following the word - ^p will find paragraph
marks and ^l will find line breaks

Signature

Enjoy,
Tony

> When I seach for a word with the code:
>
[quoted text clipped - 18 lines]
> of
> a line.
jlhamann - 06 Jan 2008 10:12 GMT
I agree, normally I would let Word flow the text, but in some languages it is
grammatically incorrect to have certain words at the end of a line.  They
need to go with the next word after them.  Word does not always flow the text
correctly.  I don’t want to go though long documents looking for these
situations.  I would like to have a macro that will find them and move the
word to the next line.  

> There is nothing you can really do about end of line per se - it is not a
> fixed position and depends on the printer.
[quoted text clipped - 27 lines]
> > of
> > a line.
Helmut Weber - 06 Jan 2008 11:28 GMT
Hi,

as this is a programmers group,
i'm assuming, you can adjust the
following to your needs.

It is just to you give you an idea
of what could be done.

But keep in mind Tony's remark.

Sub Test100a()
Dim rDcm As Range
Dim rTmp As Range
Dim lTmp As Long
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Text = "over "
  .MatchWholeWord = True
  While .Execute
     rDcm.Select
     If rDcm.Bookmarks("\line").Range.Words.Last = "over " Then
        Set rTmp = rDcm.Bookmarks("\line").Range.Words.Last
        rTmp.Select ' for testing
        lTmp = MsgBox("move?", vbYesNo)
        If lTmp = vbYes Then
           rTmp.InsertBefore Chr(11)
        End If
     End If
  Wend
End With
End Sub

Sub Test100b()
Dim rDcm As Range
Dim rTmp As Range
Dim lTmp As Long
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Text = "over "
  .MatchWholeWord = True
  While .Execute
     rDcm.Select
     If rDcm.Bookmarks("\line").Range.Words.Last = "over " Then
        Set rTmp = rDcm.Bookmarks("\line").Range.Words.Last
        rTmp.Select ' for testing
        lTmp = MsgBox("move?", vbYesNo)
        If lTmp = vbYes Then
           rTmp.Characters.Last = Chr(160)
        End If
     End If
  Wend
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Tony Jollans - 06 Jan 2008 11:42 GMT
The point is that lines (and pages) are transient objects in Word and it is
often counter-productive trying to impose your own structure. The way to do
this is to add a non-breaking space after the word(s) - instead of a normal
space. Replace "on " - without the quotes, that's o,n, space - with "on^s" -
again without the quotes, o, n, caret, s. Word will then treat "on", the
non-breaking space, and the following character(s) as one word and not end
the line with on.

Signature

Enjoy,
Tony

>I agree, normally I would let Word flow the text, but in some languages it
>is
[quoted text clipped - 38 lines]
>> > of
>> > a line.
Helmut Weber - 06 Jan 2008 14:54 GMT
Hi Tony,

sure, that's the way.

I was thinking about answering the original question
instead of thinking about the problem.

:-)

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
jlhamann - 06 Jan 2008 20:03 GMT
Thanks Tony, that was the information I needed.  

> The point is that lines (and pages) are transient objects in Word and it is
> often counter-productive trying to impose your own structure. The way to do
[quoted text clipped - 46 lines]
> >> > of
> >> > a line.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.