Range object for "current line"

R

Rick

I am trying more and more to use range objects rather than selections
when I want to format my text. Can I assign a range object to "the
current line", i.e. the line on which the insertion point rests? I'm
not sure what I would use for the starting and ending character
position. Thanks.
 
D

Doug Robbins - Word MVP

Use

Dim myrange As Range
Set myrange = Selection.Bookmarks("\line").Range
myrange.Select

The last line of the code is just to show you what it does.

Word has built in bookmarks of \word, \line and \page that can be used as
above.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
R

Rick

Thanks. At the statement

Set myrange = Selection.Bookmarks("\line").Range

I'm getting an error: "This predefined bookmark is available for the
active document only". Not sure what to make of this, as I *think*
I'm in the active document. Thanks for any help.
 
R

Rick

[answering my own question...] I am guessing I'm getting this error
because I'm in a header, not the main document body.
 
D

Doug Robbins - Word MVP

Yes, the error message could be more specific.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
[answering my own question...] I am guessing I'm getting this error
because I'm in a header, not the main document body.
 
R

Rick

Is there any way to define a range as 'the line the
insertion point is on' without using a predefined
bookmark to do so?
 
T

Tony Jollans

One way ...

Dim R As Range, S As Range
Application.ScreenUpdating = False
Set S = Selection.Range
Selection.HomeKey wdLine
Selection.EndKey wdLine, True
Set R = Selection.Range
S.Select
MsgBox R.Text
 

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

Top