Using the Word Dictionary
Setting a text range object variable equal to another text range object variable
The following instruction assigns a range variable named
to represent to the same location
set Range2 to Range1
You now have two variables that represent the same range. When you manipulate the start or end
point or the text of
, it affects
and vice versa.
Note that the following instruction is not the same as the preceding instruction. This instruction
assigns the content property of
to the content property of
. It doesn't change what the
objects actually refer to.
set content of Range2 to content of Range1
The ranges (
) have the same contents, but they may point to different locations
in the document or even to different documents.
Returning text from a document
Use the content property to return text from a text range. The following example selects the next
paragraph formatted with the Heading 1 style. The contents of the content property are displayed by
the display dialog command.
set selFind to find object of selection
clear formatting selFind
set style of selFind to style heading1
execute find selFind find text "" wrap find find stop with ¬
find format and match forward
if found of selFind is true then
display dialog (get content of text object of selection)
The following instruction returns the selected text.
set strText to content of text object of selection
The following example returns the first word in the active document. Each item in the words list is a
text range object that represents one word.
set aFirst to word 1 of text object of active document
display dialog (get content of aFirst)
The following example returns the text associated with the first bookmark in the active document.
if (count of bookmarks of active document) 1 then
set bookText to content of text object of bookmark 1 of active document
display dialog bookText