Format related procedures in class Range (Word VBA)

This page presents procedures from class Range related to the theme Format: AutoFormat, Borders, CharacterStyle, CharacterWidth, FitTextWidth, Font, FormattedText, HighlightColorIndex, Information, ListFormat, ListStyle, PageSetup, ParagraphFormat, ParagraphStyle, PasteAndFormat, Style, TableStyle and TextVisibleOnScreen

AutoFormat

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

Selection.Range.AutoFormat

Borders

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

For information about returning a single member of a collection, see Returning an object from a collection.

ActiveDocument.Range.Borders =

CharacterStyle

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

Dim strCharacterStyle As String
strCharacterStyle = ActiveDocument.Range.CharacterStyle

CharacterWidth

Returns or sets the character width of the specified range.

Possible Values are wdWidthFullWidth - Characters are displayed in full character width, wdWidthHalfWidth - Characters are displayed in half the character width.
Selection.Range.CharacterWidth = wdWidthHalfWidth

FitTextWidth

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

Selection.FitTextWidth = CentimetersToPoints(5)

Font

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

To set this property, specify an expression that returns a Font object.

ActiveDocument.Styles(wdStyleHeading1).Font.Bold = False

FormattedText

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

This property returns a Range object with the character formatting and text from the specified range or selection. Paragraph formatting is included in the Range object if there is a paragraph mark in the range or selection. When you set this property, the text in the range is replaced with formatted text. If you do not want to replace the existing text, use the Collapse method before using this property (see the first example).

ActiveDocument.Range.FormattedText =

HighlightColorIndex

Returns or sets the highlight color for the specified range.

Possible Values are wdAuto - Automatic color. Default; usually black, wdBlack - Black color, wdBlue - Blue color, wdBrightGreen - Bright green color, wdByAuthor - Color defined by document author, wdClassicBlue, wdClassicRed, wdDarkBlue - Dark blue color, wdDarkRed - Dark red color, wdDarkYellow - Dark yellow color, wdGray25 - Shade 25 of gray color, wdGray50 - Shade 50 of gray color, wdGreen - Green color, wdNoHighlight - Removes highlighting that has been applied, wdPink - Pink color, wdRed - Red color, wdTeal - Teal color, wdTurquoise - Turquoise color, wdViolet - Violet color, wdWhite - White color, wdYellow - Yellow color.
Selection.Range.HighlightColorIndex = wdNoHighlight

Information

Returns information about the specified range.

Syntax : expression.Information (Type)

Type: The information type.

If ActiveDocument.Words(10).Information(wdWithInTable) Then _ 
 ActiveDocument.Words(10).Tables(1).Select

ListFormat

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

Set myDoc = ActiveDocument 
Set myRange = _ 
 myDoc.Range(Start:= myDoc.Paragraphs(3).Range.Start, _ 
 End:=myDoc.Paragraphs(6).Range.End) 
myRange.ListFormat.ApplyOutlineNumberDefault

ListStyle

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

Dim strListStyle As String
strListStyle = ActiveDocument.Range.ListStyle

PageSetup

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

ActiveDocument.Range.PageSetup =

ParagraphFormat

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

Set myRange = Documents("MyDoc.doc").Content 
With myRange.ParagraphFormat 
 .Space2 
 .TabStops.Add Position:=InchesToPoints(.25) 
End With

ParagraphStyle

Returns a Variant that represents the style used to format a paragraph.

Dim strParagraphStyle As String
strParagraphStyle = ActiveDocument.Range.ParagraphStyle

PasteAndFormat

Pastes the selected table cells and formats them as specified.

Syntax : expression.PasteAndFormat (Type)

Type: The type of formatting to use when pasting the selected table cells.

Sub PasteChart() 
 Selection.PasteAndFormat Type:=wdChartPicture 
End Sub

Style

Returns or sets the style for the specified style. Read/write Variant.

To set this property, specify the local name of the style, an integer, a WdBuiltinStyle constant, or an object that represents the style. When you return the style for a range that includes more than one style, only the first character or paragraph style is returned.

For Each c in Selection.Characters 
 MsgBox c.Style 
Next c

TableStyle

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

Dim tblstyTableStyle As TableStyle
Set tblstyTableStyle = ActiveDocument.Range.TableStyle

TextVisibleOnScreen

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

The TextVisibleOnScreen property returns 1 if all text in the range is visible; it returns 0 if no text in the range is visible; and it returns -1 if some text in the range is visible and some is not. Text that is not visible could be, for example, text that is in a collapsed heading.

Dim lngTextVisibleOnScreen As Long
lngTextVisibleOnScreen = ActiveDocument.Range.TextVisibleOnScreen