selection lines span?

H

Helmut Weber

Hi friends,

maybe you've followed the discussion on "find line numbers".
As easy as that, it seemed, but read, what Larry reports.

I thought about this and that,
but things got more and more complicated.

Here and now I have arrived at this mystery:

Alright with the selection within one line:

With Selection
MsgBox .Characters.First.Bookmarks("\line").Range.Text
MsgBox .Characters.Last.Bookmarks("\line").Range.Text
End With

Not so if the selection spans over more than one line.

"The requested member of the collection does not exist".

Any thoughts?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber

Forgive me,

the topic was
"Determining if a selection goes to a second line"

Not my day.

Helmut weber
 
J

Jay Freedman

Hi Helmut,

It appears that VBA isn't willing to allow Selection.Characters.Last
to have any built-in bookmarks. Here's a workaround, using a Range as
a "placeholder" so the Selection can be restored after collapsing it.

Dim oRg As Range
Set oRg = Selection.Range

Selection.Collapse wdCollapseStart
MsgBox Selection.Bookmarks("\line").Range.Text

oRg.Select ' the original selection
Selection.Collapse wdCollapseEnd
MsgBox Selection.Bookmarks("\line").Range.Text

oRg.Select ' the original selection
Set oRg = Nothing

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
T

Tony Jollans

As I understand it, the "\Line" predefined bookmark only applies to the
Selection - not to other Ranges. I am, therefore, more surprised that the
first line works than that the second one doesn't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top