Information on Ranges?

P

Peter Hewett

Hi Ian

There's only one Selection object, it's always whatever is selected in the ActiveDocument.
The selection may be an insertion point or a block or text, a column of text or even non
contiguous sections of text in later version of Word. When you programmatically
move/alter the Selection object you can see it change in the document.

Range objects do the same job as the Selection object but you can have as many of them as
you want. Like the selection object they "map" part of your document. However, unlike
the Selection object moving a Range object or remapping it to a different area of the
document does not show in the document.

For this reason it's generally preferred and quicker to use a Range object as this does
not cause screen updates when you change its mapping.

For some reason the Selection object supports more properties/methods than a Range object.
That's why when you see people asking about moving through a document line-by-line you'll
see the Selection object used, something like this:

Public Sub ReadDocLineByLine()
Selection.HomeKey wdStory
Do
Selection.MoveEnd (wdLine)
MsgBox "(" & Len(Selection.Text) & ") " & Selection.Text
Loop Until Selection.MoveStart(wdLine, 1) = 0
End Sub

That's because you can't use wdLine with a Range object.

For performance reasons and to avoid flickery screen updates wherever possible I use Range
objects. I prefer the aesthetics as well!

I need to find out more about working with Ranges. Pointers anyone?

HTH + Cheers - Peter
 
I

Ian

Thanks Peter. Very helpful as usual.

--
Ian


Peter Hewett said:
Hi Ian

There's only one Selection object, it's always whatever is selected in
the ActiveDocument.
The selection may be an insertion point or a block or text, a column of
text or even non
contiguous sections of text in later version of Word. When you
programmatically
move/alter the Selection object you can see it change in the document.

Range objects do the same job as the Selection object but you can have
as many of them as
you want. Like the selection object they "map" part of your document.
However, unlike
the Selection object moving a Range object or remapping it to a
different area of the
document does not show in the document.

For this reason it's generally preferred and quicker to use a Range
object as this does
not cause screen updates when you change its mapping.

For some reason the Selection object supports more properties/methods
than a Range object.
That's why when you see people asking about moving through a document
line-by-line you'll
see the Selection object used, something like this:

Public Sub ReadDocLineByLine()
Selection.HomeKey wdStory
Do
Selection.MoveEnd (wdLine)
MsgBox "(" & Len(Selection.Text) & ") " & Selection.Text
Loop Until Selection.MoveStart(wdLine, 1) = 0
End Sub

That's because you can't use wdLine with a Range object.

For performance reasons and to avoid flickery screen updates wherever
possible I use Range
objects. I prefer the aesthetics as well!



HTH + Cheers - Peter
 

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