Formatting Text

The Range object's properties also include many of the standard text formatting commands. For example, the Bold property returns True if the Range object is formatted entirely as bold, returns False if no part of the range is bold, and returns wdUndefined if only part of the range is formatted as bold. You can also set this property by using True (for bolding), False (to remove bolding), or wdToggle (to toggle the current setting between True and False).

A similar property is Italic, which returns True if the specified range is formatted entirely as italic, returns False if no part of the range is italic, and returns wdUndefined if only part of the range is formatted as italic. You can also set this property by using True (for italics), False (to remove italics), or wdToggle (to toggle the current setting between True and False).

Another useful property is Case, which returns or sets the case of the specified range. This property uses various wdCharacterCase constants, including wdLowerCase, wdTitleSentence, wdTitleWord, wdToggleCase, and wdUpperCase.

For example, the following code fragment takes the Range object of the active document's first paragraph, and then sets Bold to True, Italic to True, and the case to wdTitleWord:

With ActiveDocument.Paragraphs(1).Range .Bold = True .Italic = True .Case = wdTitleWord End With

If you want maximum control over the character formatting in a range, use the Font property, which returns a Font object. From there you can manipulate not only the Bold and Italic properties, but also the type size (the Size property), the color (Color), strikethrough (StrikeThrough and DoubleStrikeThrough), small caps (SmallCaps), and much more. Here's an example:

With ActiveDocument.Range.Font .Color = RGB(0, 0, 255) .Size = 12 .SmallCaps = True End With

0 0

Post a comment