Class Range (Word VBA)

The class Range represents a contiguous area in a document. Each Range object is defined by a starting and ending character position.

The classes AutoTextEntry, Bookmark, Break, BuildingBlock, Cell, CoAuthLock, CoAuthUpdate, Comment, Conflict, ContentControl, Document, Editor, Endnote, Envelope ... give access to class RangeField, Footnote, FormField, Frame, HeaderFooter, HTMLDivision, Hyperlink, Index, InlineShape, Line, List, MailMergeField, OMath, OMathBreak, OMathFunction, Paragraph, Rectangle, RepeatingSectionItem, Revision, Row, Section, Selection, Series, Shape, Subdocument, Table, TableOfAuthorities, TableOfContents, TableOfFigures, TextFrame, Window, XMLNode.

Dim rng as Range
Set rng = ActiveDocument.Range()

For Each

Here is an example of processing the Range items in a collection.


Dim rngCharacter As Range
Dim iFontSize As Integer: iFontSize = 8
For Each rngCharacter In ActiveDocument.Words(1).Characters
    rngCharacter.Font.Size = iFontSize
    iFontSize = iFontSize + 2
Next rngCharacter

Methods

AutoFormat - Automatically formats a document. Use the Kind property to specify a document type.

Calculate - Calculates a mathematical expression within a range or selection. Returns the result as a Single.

CheckGrammar - Begins a spelling and grammar check for the specified range.

CheckSpelling - Begins a spelling check for the specified document or range.

CheckSynonyms - Displays the Thesaurus dialog box, which lists alternative word choices, or synonyms, for the text in the specified range.

Collapse - Collapses a range or selection to the starting or ending position. After a range or selection is collapsed, the starting and ending points are equal.

ComputeStatistics - Returns a Long that represents a statistic based on the contents of the specified range.

ConvertHangulAndHanja - Converts the specified range from hangul to hanja or vice versa.

ConvertToTable - Converts text within a range to a table. Returns the table as a Table object.

Copy - Copies the specified range to the Clipboard.

CopyAsPicture - The CopyAsPicture method works the same way as the Copy method.

Cut - Removes the specified object from the document and places it on the Clipboard.

Delete - Deletes the specified number of characters or words.

DetectLanguage - Analyzes the specified text to determine the language that it is written in.

EndOf - Moves or extends the ending character position of a range to the end of the nearest specified text unit.

Expand - Expands the specified range or selection. Returns the number of characters added to the range or selection.

ExportAsFixedFormat - Saves a portion of a document as PDF or XPS format.

ExportAsFixedFormat2 - Saves a portion of a document as PDF or XPS format.

ExportFragment - Exports the selected range into a document for use as a document fragment.

GetSpellingSuggestions - Returns a SpellingSuggestions collection that represents the words suggested as spelling replacements for the first word in the specified range.

GoTo - Returns a Range object that represents the start position of the specified item, such as a page, bookmark, or field.

GoToEditableRange - Returns a Range object that represents an area of a document that can be modified by the specified user or group of users.

GoToNext - Returns a Range object that refers to the start position of the next item or location specified by the What argument.

GoToPrevious - Returns a Range object that refers to the start position of the previous item or location specified by the What argument.

ImportFragment - Imports a document fragment into the document at the specified range.

InRange - Returns True if the range to which the method is applied is contained in the range specified by the Range argument.

InsertAfter - Inserts the specified text at the end of a range.

InsertAlignmentTab - Inserts an absolute tab that is always positioned in the same spot, relative to either the margins or indents.

InsertAutoText - Attempts to match the text in the specified range or the text surrounding the range with an existing AutoText entry name.

InsertBefore - Inserts the specified text before the specified range.

InsertBreak - Inserts a page, column, or section break.

InsertCaption - Inserts a caption immediately preceding or following the specified range.

InsertCrossReference - Inserts a cross-reference to a heading, bookmark, footnote, or endnote, or to an item for which a caption label is defined (for example, an equation, figure, or table).

InsertDatabase - Retrieves data from a data source (for example, a separate Microsoft Word document, a Microsoft Excel worksheet, or a Microsoft Access database) and inserts the data as a table in place of the specified range.

InsertDateTime - Inserts the current date or time, or both, either as text or as a TIME field.

InsertFile - Inserts all or part of the specified file.

InsertParagraph - Replaces the specified range with a new paragraph.

InsertParagraphAfter - Inserts a paragraph mark after a range.

InsertParagraphBefore - Inserts a new paragraph before the specified range.

InsertSymbol - Inserts a symbol in place of the specified range.

InsertXML - Inserts the specified XML into the document at the specified range, replacing any text contained within the range.

InStory - True if the range to which this method is applied is in the same story as the range specified by the Range argument.

IsEqual - True if the range to which this method is applied is equal to the range specified by the Range argument.

LookupNameProperties - Looks up a name in the global address book list and displays the Properties dialog box, which includes information about the specified name.

ModifyEnclosure - Adds, modifies, or removes an enclosure around the specified character or characters.

Move - Collapses the specified range to its start or end position and then moves the collapsed object by the specified number of units.

MoveEnd - Moves the ending character position of a range.

MoveEndUntil - Moves the end position of the specified range until any of the specified characters are found in the document. If the movement is forward in the document, the range is expanded.

MoveEndWhile - Moves the ending character position of a range while any of the specified characters are found in the document.

MoveStart - Moves the start position of the specified range.

MoveStartUntil - Moves the start position of the specified range until one of the specified characters is found in the document.

MoveStartWhile - Moves the start position of the specified range while any of the specified characters are found in the document.

MoveUntil - Moves the specified range until one of the specified characters is found in the document.

MoveWhile - Moves the specified range while any of the specified characters are found in the document.

Next - Returns a Range object that represents the specified unit relative to the specified range.

NextSubdocument - Moves the range to the next subdocument.

Paste - Inserts the contents of the Clipboard at the specified range.

PasteAndFormat - Pastes the selected table cells and formats them as specified.

PasteAppendTable - Merges pasted cells into an existing table by inserting the pasted rows between the selected rows. No cells are overwritten.

PasteAsNestedTable - Pastes a cell or group of cells as a nested table into the selected range.

PasteExcelTable - Pastes and formats a Microsoft Excel table.

PasteSpecial - Inserts the contents of the Clipboard.

PhoneticGuide - Adds phonetic guides to the specified range.

Previous - Returns the previous range a relative to the specified range.

PreviousSubdocument - Moves the range to the previous subdocument.

Relocate - In outline view, moves the paragraphs within the specified range after the next visible paragraph or before the previous visible paragraph.

Select - Selects the specified range.

SetListLevel - Sets the list level for one or more items in a numbered list.

SetRange - Sets the starting and ending character positions for an existing range.

Sort - Sorts the paragraphs in the specified range.

SortAscending - Sorts paragraphs or table rows in ascending alphanumeric order.

SortByHeadings - Sorts the headings in the specified range.

SortDescending - Sorts paragraphs in descending alphanumeric order.

StartOf - Moves or extends the start position of the specified range or selection to the beginning of the nearest specified text unit. This method returns a Long that indicates the number of characters by which the range or selection was moved or extended. The method returns a negative number if the movement is backward through the document.

TCSCConverter - Converts the specified range from Traditional Chinese to Simplified Chinese or vice versa.

WholeStory - Expands a range to include the entire story.

Properties

Text (Default member) - Returns or sets the text in the specified range or selection. Read/write String.

Bold true if the range is formatted as bold.

BoldBi true if the font or range is formatted as bold. Returns True, False, or wdUndefined (for a mixture of bold and non-bold text). Can be set to True, False, or wdToggle.

BookmarkID returns the number of the bookmark that encloses the beginning of the specified range; returns 0 (zero) if there is no corresponding bookmark.

Bookmarks returns a Bookmarks collection that represents all the bookmarks in a document, range, or selection.

Borders returns a Borders collection that represents all the borders for the specified object.

Case returns or sets a WdCharacterCase constant that represents the case of the text in the specified range.

Cells returns a Cells collection that represents the table cells in a range.

Characters returns a Characters collection that represents the characters in a range.

CharacterStyle returns a Variant that represents the style used to format one or more characters.

CharacterWidth returns or sets the character width of the specified range.

Columns returns a Columns collection that represents all the table columns in the range.

CombineCharacters true if the specified range contains combined characters.

Comments returns a Comments collection that represents all the comments in the specified document, selection, or range.

Conflicts returns a Conflicts collection object that contains all the conflict objects in the range.

ContentControls returns a ContentControls collection that represents the content controls contained within a range.

DisableCharacterSpaceGrid true if Microsoft Word ignores the number of characters per line for the corresponding Range object.

Document returns a Document object associated with the specified range.

Duplicate returns a read-only Range object that represents all the properties of the specified range.

Editors returns an Editors object that represents all the users authorized to modify a selection or range within a document.

EmphasisMark returns or sets the emphasis mark for a character or designated character string.

End returns or sets the ending character position of a range.

EndnoteOptions returns an EndnoteOptions object that represents the endnotes in a range.

Endnotes returns an Endnotes collection that represents all the endnotes in a range.

EnhMetaFileBits returns a Variant that represents a picture representation of how a range of text appears.

Fields returns a Fields collection that represents all the fields in the range.

Find returns a Find object that contains the criteria for a find operation.

FitTextWidth returns or sets the width (in the current measurement units) in which Microsoft Word fits the text in the current selection or range.

Font returns or sets a Font object that represents the character formatting of the specified object.

FootnoteOptions returns FootnoteOptions object that represents the footnotes in a selection or range.

Footnotes returns a Footnotes collection that represents all the footnotes in a range.

FormattedText returns or sets a Range object that includes the formatted text in the specified range or selection.

FormFields returns a FormFields collection that represents all the form fields in the range.

Frames returns a Frames collection that represents all the frames in a range.

GrammarChecked true if a grammar check has been run on the specified range or document.

GrammaticalErrors returns a ProofreadingErrors collection that represents the sentences that failed the grammar check on the specified document or range.

HighlightColorIndex returns or sets the highlight color for the specified range.

HorizontalInVertical returns or sets the formatting for horizontal text set within vertical text.

HTMLDivisions returns an HTMLDivisions object that represents an HTML division in a web document.

Hyperlinks returns a Hyperlinks collection that represents all the hyperlinks in the specified range.

ID returns or sets the identification name for the specified range.

Information returns information about the specified range.

InlineShapes returns an InlineShapes collection that represents all the InlineShape objects in a range.

IsEndOfRowMark true if the specified range is collapsed and is located at the end-of-row mark in a table.

Italic true if the font or range is formatted as italic.

ItalicBi true if the font or range is formatted as italic.

Kana returns or sets whether the specified range of Japanese language text is hiragana or katakana.

LanguageDetected returns or sets a value that specifies whether Microsoft Word has detected the language of the specified text.

LanguageID returns or sets a WdLanguageID constant that represents the language for the specified range.

LanguageIDFarEast returns or sets an East Asian language for the specified object.

LanguageIDOther returns or sets the language for the specified range.

ListFormat returns a ListFormat object that represents all the list formatting characteristics of a range.

ListParagraphs returns a ListParagraphs collection that represents all the numbered paragraphs in the range.

ListStyle returns a Variant that represents the style used to format a bulleted list or numbered list.

Locks returns a CoAuthLocks collection object that represents all the locks in the range.

NextStoryRange returns a Range object that refers to the next story.

NoProofing true if the spelling and grammar checker ignores the specified text.

OMaths returns an OMaths collection that represents the OMath objects within the specified range.

Orientation returns or sets the orientation of text in a range when the Text Direction feature is enabled.

PageSetup returns a PageSetup object that's associated with the specified range.

ParagraphFormat returns or sets a ParagraphFormat object that represents the paragraph settings for the specified range.

Paragraphs returns a Paragraphs collection that represents all the paragraphs in the specified range.

ParagraphStyle returns a Variant that represents the style used to format a paragraph.

Parent returns an object that represents the parent object of the specified Range object.

ParentContentControl returns a ContentControl object that represents the parent content control for the specified range.

PreviousBookmarkID returns the number of the last bookmark that starts before or at the same place as the specified range.

ReadabilityStatistics returns a ReadabilityStatistics collection that represents the readability statistics for the specified document or range.

Revisions returns a Revisions collection that represents the tracked changes in the range.

Rows returns a Rows collection that represents all the table rows in a range.

Scripts returns a Scripts collection that represents the collection of HTML scripts in the specified object.

Sections returns a Sections collection that represents the sections in the specified range.

Sentences returns a Sentences collection that represents all the sentences in the range.

Shading returns a Shading object that refers to the shading formatting for the specified object.

ShapeRange returns a ShapeRange collection that represents all the Shape objects in the specified range.

ShowAll true if all nonprinting characters (such as hidden text, tab marks, space marks, and paragraph marks) are displayed.

SpellingChecked true if spelling has been checked throughout the specified range or document. False if all or some of the range or document has not been checked for spelling.

SpellingErrors returns a ProofreadingErrors collection that represents the words identified as spelling errors in the specified range.

Start returns or sets the starting character position of a range.

StoryLength returns the number of characters in the story that contains the specified range.

StoryType returns the story type for the specified range, selection, or bookmark.

Style returns or sets the style for the specified style. Read/write Variant.

Subdocuments returns a Subdocuments collection that represents all the subdocuments in the specified range or document.

SynonymInfo returns a SynonymInfo object that contains information from the thesaurus on synonyms, antonyms, or related words and expressions for the contents of a range.

Tables returns a Tables collection that represents all the tables in the specified range.

TableStyle returns a Variant that represents the style used to format a table. Read-only.

TextRetrievalMode returns a TextRetrievalMode object that controls how text is retrieved from the specified Range.

TextVisibleOnScreen returns a Long that indicates whether the text in the specified range is visible on the screen.

TopLevelTables returns a Tables collection that represents the tables at the outermost nesting level in the current range.

TwoLinesInOne returns or sets whether Microsoft Word sets two lines of text in one and specifies the characters that enclose the text, if any.

Underline returns or sets the type of underline applied to a range.

Updates returns a CoAuthUpdates collection object that represents all updates that were merged into the specified range at the last explicit save.

WordOpenXML returns a String that represents the XML contained within the range in the Microsoft Word Open XML format.

Words returns a Words collection that represents all the words in a range.

XML returns a String that represents the XML text in the specified object.

Bookmarks - A collection of Bookmark objects that represent the bookmarks in the specified selection, range, or document.

Borders - A collection of Border objects that represent the borders of an object.

Cells - A collection of Cell objects in a table column, table row, selection, or range.

Characters - A collection of characters in a selection, range, or document. There is no Character object; instead, each item in the Characters collection is a Range object that represents one character.

CoAuthLocks - A collection of CoAuthLock objects.

CoAuthUpdates - A collection of CoAuthUpdate objects that represent the updates that were merged into the document at the last explicit save.

Columns - A collection of Column objects that represent the columns in a table.

Comments - A collection of Comment objects that represent the comments in a selection, range, or document.

Conflicts - A collection ofConflict objects that represents the conflicts in a document. The type of a Conflict object is specified by the WdRevisionType enumeration.

ContentControl - An individual content control. Content controls are bounded and potentially labeled regions in a document that serve as containers for specific types of content. Individual content controls may contain contents such as dates, lists, or paragraphs of formatted text. The ContentControl object is a member of the ContentControls collection.

ContentControls - A collection of ContentControl objects. Content controls are bounded and potentially labeled regions in a document that serve as containers for specific types of content. Individual content controls may contain content such as dates, lists, or paragraphs of formatted text.

Document - Represents a document. The Document object is a member of the Documents collection. The Documents collection contains all the Document objects that are currently open in Word.

Editors - A collection of Editor objects that represents a collection of users or groups of users who have been given specific permissions to edit portions of a document.

EndnoteOptions - Represents the properties assigned to a range or selection of endnotes in a document.

Endnotes - A collection of Endnote objects that represents all the endnotes in a selection, range, or document.

Fields - A collection of Field objects that represent all the fields in a selection, range, or document.

Find - Represents the criteria for a find operation.

Font - Contains font attributes (such as font name, font size and color) for an object.

FootnoteOptions - Represents the properties assigned to a range or selection of footnotes in a document.

Footnotes - A collection of Footnote objects that represent all the footnotes in a selection, range, or document.

FormFields - A collection of FormField objects that represent all the form fields in a selection, range, or document.

Frames - Word Object Model Reference

HTMLDivisions - A collection of HTMLDivision objects that represents the HTML DIV elements that exist in a web document.

Hyperlinks - Represents the collection of Hyperlink objects in a document, range, or selection.

InlineShapes - A collection of InlineShape objects that represent all the inline shapes in a document, range, or selection.

ListFormat - Represents the list formatting attributes that can be applied to the paragraphs in a range.

ListParagraphs - A collection of Paragraph objects that represents the paragraphs of the specified document, list, or range that have list formatting applied.

OMaths - A collection of equations. Use the OMath object to access individual members of the collection.

PageSetup - Represents the page setup description. The PageSetup object contains all the page setup attributes of a document (such as left margin, bottom margin, and paper size) as properties.

ParagraphFormat - Represents all the formatting for a paragraph.

Paragraphs - A collection of Paragraph objects in a selection, range, or document.

ProofreadingErrors - A collection of spelling and grammatical errors for the specified document or range.

ReadabilityStatistics - A collection of ReadabilityStatistic objects for a document or range.

Revisions - A collection of Revision objects that represent the changes marked with revision marks in a range or document.

Rows - A collection of Row objects that represent the table rows in the specified selection, range, or table.

Sections - A collection of Section objects in a selection, range, or document.

Sentences - A collection of Range objects that represent all the sentences in a selection, range, or document. There is no Sentence object.

Shading - Contains shading attributes for an object.

ShapeRange - Represents a shape range, which is a set of shapes on a document. A shape range can contain as few as one shape or as many as all the shapes in the document.

SpellingSuggestions - A collection of SpellingSuggestion objects that represent all the suggestions for a specified word or for the first word in the specified range.

Style - Represents a single built-in or user-defined style. The Style object includes style attributes (such as font, font style, and paragraph spacing) as properties of the Style object. The Style object is a member of the Styles collection. The Styles collection includes all the styles in the specified document.

Subdocuments - A collection of Subdocument objects that represent the subdocuments in a range or document.

SynonymInfo - Represents the information about synonyms, antonyms, related words, or related expressions for the specified range or a given string.

Table - Represents a single table. The Table object is a member of the Tables collection. The Tables collection includes all the tables in the specified selection, range, or document.

Tables - A collection of Table objects that represent the tables in a selection, range, or document.

TableStyle - Represents a single style that can be applied to a table.

TextRetrievalMode - Represents options that control how text is retrieved from a Range object.

Words - A collection of words in a selection, range, or document. Each item in the Words collection is a Range object that represents one word. There is no Word object.