Formatting paragraphs
Paragraphs are a key concept in Word. Much of Word s formatting can be thought of as being stored "in" the marker that follows each paragraph. That s why moving text sometimes changes its formatting. If you fail to take the paragraph marker along, the moved text picks up the formatting of the new location.
At the paragraph level, you can determine alignment of text (left, right, centered, or full justification), various kinds of indentation (both amount and type), spacing of lines and paragraphs, handling of widow and orphans, and much more. Word allows regular indentation from both the left and right margins, as well as first line indents and hanging indents. Interactively, all of this is managed by the Paragraph dialog on the Format menu (shown in Figure 5). Behind the scenes, the ParagraphFormat object controls these settings.
Range, Selection, and Style, among others, have a ParagraphFormat object, accessed through the ParagraphFormat property. The Paragraph object has a Format property that accesses a ParagraphFormat object.
Figure 5
. The Paragraph dialog. The Indents and Spacing page shown here lets you indicate alignment, indentation, and spacing. The Line and Page Breaks page handles widow and orphan control and automatic hyphenation. The ParagraphFormat object controls these settings for Automation.Table 4
shows some commonly used properties of the ParagraphFormat object and the frequently used constant values for them. Like many of Word s objects, ParagraphFormat has only a few methods; none are likely to be useful in most Automation code.This example sets the first paragraph in the current range to have a 0.5" first line indent, widow and orphan control, double spacing, and full justification:
#DEFINE wdAlignParagraphJustify 3
#DEFINE wdLineSpaceDouble 2
WITH oRange.Paragraphs[1].Format
.FirstLineIndent = oWord.InchesToPoints( .5 )
.WidowControl = .T.
.Alignment = wdAlignParagraphJustify
.LineSpacingRule = wdLineSpaceDouble
ENDWITH
This example triple spaces a range:
#DEFINE wdLineSpaceMultiple 5
WITH oRange.ParagraphFormat
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = oWord.LinesToPoints( 3 )
ENDWITH
Table 4
. ParagraphFormat properties. Property | Type | Description |
Alignment | Numeric | The alignment of text in the paragraph. wdAlignParagraphLeft 0 wdAlignParagraphRight 2 wdAlignParagraphCenter 1 wdAlignParagraphJustify 3
|
LeftIndent | Numeric | The indentation of the left edge of this paragraph from the left margin, in points. |
RightIndent | Numeric | The indentation of the right edge of this paragraph from the right margin, in points. |
FirstLineIndent | Numeric | The indentation of the first line of the paragraph. This property determines whether the paragraph has the first line indented or "outdented" (providing a hanging indent). Set a positive value to indent the first line, 0 to keep the first line flush with the rest of the paragraph, or a negative value for a hanging indent. Note that, with a hanging indent, the first line doesn t move to the left; subsequent lines move to the right. |
SpaceBefore, SpaceAfter | Numeric | The amount of white space (known as leading) before and after the paragraph, in points. |
LineSpacingRule | Numeric | The kind of line spacing in effect. This setting can entirely determine the line spacing, or it can set the stage for the LineSpacing property. wdLineSpaceSingle 0 wdLineSpaceAtLeast 3 wdLineSpaceDouble 2 wdLineSpace1pt5 1 wdLineSpaceExactly 4 wdLineSpaceMultiple 5
|
LineSpacing | Numeric | The actual line spacing, in points, when LineSpacingRule is wdLineSpaceAtLeast, wdLineSpaceExactly, or wdLineSpaceMultiple. |
WidowControl | Numeric or Logical | Indicates whether the first and last lines of the paragraph are kept on the same page as the rest of the paragraph. |
KeepTogether | Numeric or Logical | Indicates whether the entire paragraph is kept on a single page. |
KeepWithNext | Numeric or Logical | Indicates whether the paragraph is kept on the same page with the paragraph that follows it. |
Hyphenation | Numeric or Logical | Indicates whether the paragraph is hyphenated automatically. |
Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved