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 2006

Tip: Looking for answers? Try searching our database.

Determining if a selection goes to a second line

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry - 04 Jan 2006 17:45 GMT
How would you deterine if a multiword selection extends over more than
one line?  In other words, a selection begins with a couple of words at
the end of one line, and continues to a couple of words on the next
line.  I've been trying the Information property, but can't find any way
to make it work.  The wdFirstCharacterColumnNumber it only gives you the
column number for the first character in the selection.  Also, I haven't
been able to get wdFirstCharacterLineNumber to work at all.

Thanks,
Larry
Greg - 04 Jan 2006 20:16 GMT
Larry,

Just a stab, but try:
Sub Test()
Dim oRng As Range
Dim x As Long
Dim y As Long
y = Selection.Information(wdFirstCharacterLineNumber)

Set oRng = Selection.Range
oRng.Start = Selection.Range.End - 1
oRng.End = Selection.Range.End
x = oRng.Information(wdFirstCharacterLineNumber)
If x - y > 1 Then
 MsgBox "The selection spans more than one line."
End If
End Sub
Helmut Weber - 04 Jan 2006 21:34 GMT
Hi Greg,

a happy new year to you, submariner!

I guess, you'll like that:

Sub Macro5()
' 10 = wdFirstCharacterLineNumber
With Selection.Characters
  If .First.Information(10) <> _
     .Last.Information(10) Then
     MsgBox "not in same line"
  End If
End With
End Sub

Plus the switching of views beforehand,
in a quick and dirty way, like:

With ActiveWindow.View
  If .Type = wdNormalView Then
     .Type = wdPrintView
     .Type = wdNormalView
  End If
  If .Type = wdPrintView Then
     .Type = wdNormalView
     .Type = wdPrintView
  End If
End With

By the way, once views have been switched once
in a working session for a doc, the problem,
that wdFirstCharacterLineNumber returns -1
has gone, IMHO.
Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg Maxey - 04 Jan 2006 22:40 GMT
Helmut,

Happy New Year.

Yep your way is nifty and far superior ;-)

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Greg,
>
[quoted text clipped - 30 lines]
> that wdFirstCharacterLineNumber returns -1
> has gone, IMHO.
Larry - 05 Jan 2006 15:12 GMT
Funny, I thought I replied yesterday, but the message isn't here.

Anyway, neither Helmut nor Greg's suggestion worked.  There seems to be
a problem with using range with the Information property.  It works with
Selection not Range.  So I came up with this, which is awfully clunky.
I added a step which selects the range oRng, and then get its
Information, and then return the selection to the original selection:

Application.ScreenUpdating = False

Dim oRng As Range, r As Range
Dim x As Long
Dim y As Long
y = Selection.Information(wdFirstCharacterLineNumber)
Set r = Selection.Range
Set oRng = Selection.Range

oRng.Start = Selection.Range.End - 1
oRng.End = Selection.Range.End

' I had to add this line, actually selecting the range because this only
works
' with selections, not ranges.

oRng.Select
x = Selection.Information(wdFirstCharacterLineNumber)

'x = oRng.Information(wdFirstCharacterLineNumber)
'MsgBox y & " " & x

If x - y > 0 Then
r.Select
End If

> Hi Greg,
>
[quoted text clipped - 30 lines]
> that wdFirstCharacterLineNumber returns -1
> has gone, IMHO.
Helmut Weber - 05 Jan 2006 15:31 GMT
Hi Larry,

forgive me, but for your question
>multiword selection extends over more than one line
there were two working solutions.

>It works with Selection not Range.

See above.  ;-)

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Larry - 06 Jan 2006 05:26 GMT
Helmut,

Yesterday I tried this every way I could think of, and it didn't work.
Now it's working.  Thanks.

Also, I got confused on the selection/range issue because ... well, it's
too complicated to explain.... :-)

' 10 = wdFirstCharacterLineNumber
With Selection.Characters
  If .First.Information(10) <> _
     .Last.Information(10) Then
     MsgBox "not in same line"
  End If
End With

> Hi Larry,
>
[quoted text clipped - 5 lines]
>
> See above.  ;-)
Helmut Weber - 04 Jan 2006 20:41 GMT
Hi Larry,

>Also, I haven't been able to get
>wdFirstCharacterLineNumber to work at all.

switch views beforehand,
from normal view to print layout and back
or the other way round, doesn't matter which way.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

 
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.