Etudes for Microsoft Word Programmers. Appendix.


Information on this page is from Microsoft MSDN http://msdn.microsoft.com.

ParagraphFormat (Word 2003)

Object ParagraphFormat

Represents all the formatting for a paragraph.

Using the ParagraphFormat Object

Use the Format property to return the ParagraphFormat object for a paragraph or paragraphs. The ParagraphFormat property returns the ParagraphFormat object for a selection, range, style, Find object, or Replacement object. The following example centers the third paragraph in the active document.

ActiveDocument.Paragraphs(3).Format.Alignment = wdAlignParagraphCenter

The following example finds the next double-spaced paragraph after the selection.

With Selection.Find
     .ClearFormatting
     .ParagraphFormat.LineSpacingRule = wdLineSpaceDouble
     .Text = ""
     .Forward = True
     .Wrap = wdFindContinue
 End With
 Selection.Find.Execute

You can use Visual Basic's New keyword to create a new, standalone ParagraphFormat object. The following example creates a ParagraphFormat object, sets some formatting properties for it, and then applies all of its properties to the first paragraph in the active document.

Dim myParaF As New ParagraphFormat
 myParaF.Alignment = wdAlignParagraphCenter
 myParaF.Borders.Enable = True
 ActiveDocument.Paragraphs(1).Format = myParaF

You can also make a standalone copy of an existing ParagraphFormat object by using the Duplicate property. The following example duplicates the paragraph formatting of the first paragraph in the active document and stores the formatting in myDup. The example changes the left indent of myDup to 1 inch, creates a new document, inserts text into the document, and applies the paragraph formatting of myDup to the text.

Set myDup = ActiveDocument.Paragraphs(1).Format.Duplicate
 myDup.LeftIndent = InchesToPoints(1)
 Documents.Add
 Selection.InsertAfter "This is a new paragraph."
 
Selection.Paragraphs.Format = myDup

ParagraphFormat Object Properties

ParagraphFormat object properties are described in the following table.

Property

Type

Description

Alignment

Read/write
WdParagraph Alignment

Returns or sets a WdParagraphAlignment constant that represents the alignment for the specified paragraphs.

AutoAdjustRightIndent

Read/write Long

True if Microsoft Word is set to automatically adjust the right indent for the specified paragraphs if youve specified a set number of characters per line. Returns wdUndefined if the AutoAdjustRightIndent property is set to True for only some of the specified paragraphs.

BaseLineAlignment

WdBaselineAlignment
Read/write

Returns or sets a WdBaselineAlignment constant that represents the vertical position of fonts on a line.

Borders

Borders Collection

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

CharacterUnit FirstLineIndent

Read/write Single

Returns or sets the value (in characters) for a first-line or hanging indent. Use a positive value to set a first-line indent, and use a negative value to set a hanging indent.

CharacterUnit LeftIndent

Read/write Single

Returns or sets the left indent value (in characters) for the specified paragraphs.

CharacterUnit RightIndent

Read/write Single

Returns or sets the right indent value (in characters) for the specified paragraphs.

DisableLineHeightGrid

Read/write Long

True if Microsoft Word aligns characters in the specified paragraphs to the line grid when a set number of lines per page is specified. Returns wdUndefined if the DisableLineHeightGrid property is set to True for only some of the specified paragraphs.

Duplicate

read-only
Object ParagraphFormat

Returns a read-only ParagraphFormat object that represents the paragraph formatting of the specified paragraph.

You can use the Duplicate property to pick up the settings of all the properties of a duplicated Font, LetterContent, or ParagraphFormat object. You can assign the object returned by the Duplicate property to another object of the same type to apply those settings all at once. Before assigning the duplicate object to another object, you can change any of the properties of the duplicate object without affecting the original.

FirstLineIndent

Read/write Single

Returns or sets the value (in points) for a first line or hanging indent. Use a positive value to set a first-line indent, and use a negative value to set a hanging indent.

HalfWidthPunctuation OnTopOfLine

Read/write Long

True if Microsoft Word changes punctuation symbols at the beginning of a line to half-width characters for the specified paragraphs. This property returns wdUndefined if its set to True for only some of the specified paragraphs.

HangingPunctuation

Read/write Long

True if hanging punctuation is enabled for the specified paragraphs. This property returns wdUndefined if its set to True for only some of the specified paragraphs.

Hyphenation

Read/write Long

True if the specified paragraphs are included in automatic hyphenation. False if the specified paragraphs are to be excluded from automatic hyphenation. Can be True, False or wdUndefined.

KeepTogether

Read/write Long

True if all lines in the specified paragraphs remain on the same page when Microsoft Word repaginates the document. Can be True, False, or wdUndefined.

KeepWithNext

Read/write Long

True if the specified paragraph remains on the same page as the paragraph that follows it when Microsoft Word repaginates the document. Can be True, False, or wdUndefined.

LeftIndent

Read/write Single

Returns or sets a Single that represents the left indent value (in points) for the specified paragraphs, table rows, or HTML division.

LineSpacing

Read/write Single

Returns or sets the line spacing (in points) for the specified paragraphs.

The LineSpacing property can be set after the LineSpacingRule property has been set to:
wdLineSpaceAtLeast the line spacing can be greater than or equal to, but never less than, the specified LineSpacing value.
wdLineSpaceExactly the line spacing never changes from the specified LineSpacing value, even if a larger font is used within the paragraph.
wdLineSpaceMultiple    a LineSpacing property value must be specified, in points.

Use the LinesToPoints method to convert a number of lines to the corresponding value in points. For example, LinesToPoints(2) returns the value 24.

LineSpacingRule

Read/write WdLineSpacing

Returns or sets the line spacing for the specified paragraphs.

Use wdLineSpaceSingle, wdLineSpace1pt5, or wdLineSpaceDouble to set the line spacing to one of these values. To set the line spacing to an exact number of points or to a multiple number of lines, you must also set the LineSpacing property.

LineUnitAfter

Read/write Single

Returns or sets the amount of spacing (in gridlines) after the specified paragraphs.

LineUnitBefore

Read/write Single

Returns or sets the amount of spacing (in gridlines) before the specified paragraphs.

NoLineNumber

Read/write Long

True if line numbers are repressed for the specified paragraphs. Can be True, False, or wdUndefined.

Use the LineNumbering property to set line numbers.

OutlineLevel

Read/write wdOutlineLevel

Returns or sets the outline level for the specified paragraphs.

If a paragraph has a heading style applied to it (Heading 1 through Heading 9), the outline level is the same as the heading style and cannot be changed.
Outline levels are visible only in outline view or the document map pane.

PageBreakBefore

Read/write Long

True if a page break is forced before the specified paragraphs. Can be True, False, or wdUndefined.

RightIndent

Read/write Single

Returns or sets the right indent (in points) for the specified paragraphs.

Shading

Object Shading

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

SpaceAfter

Read/write Single

Returns or sets the amount of spacing (in points) after the specified paragraph or text column.

SpaceAfterAuto

Read/write Long

True if Microsoft Word automatically sets the amount of spacing after the specified paragraphs. Returns wdUndefined if the SpaceAfterAuto property is set to True for only some of the specified paragraphs. Can be set to either True or False.

When you open an HTML document without cascading style sheets, Word automatically sets the SpaceAfterAuto property to True to render the paragraph spacing exactly as it would appear in a Web browser.

If SpaceAfterAuto is set to True, the SpaceAfter property is ignored.

SpaceBefore

Read/write Single

Returns or sets the spacing (in points) before the specified paragraphs.

SpaceBeforeAuto

Read/write Long

True if Microsoft Word automatically sets the amount of spacing before the specified paragraphs. Returns wdUndefined if the SpaceBeforeAuto property is set to True for only some of the specified paragraphs. Can be set to either True or False.

When you open an HTML document without cascading style sheets, Word automatically sets the SpaceBeforeAuto property to True to render the paragraph spacing exactly as it would appear in a Web browser.

If SpaceBeforeAuto is set to True, the SpaceBefore property is ignored.

Style

Read/write Variant

Returns or sets the style for the specified object. To set this property, specify the local name of the style, an integer, a WdBuiltinStyle constant, or an object that represents the style. For a list of valid constants, consult the Microsoft Visual Basic Object Browser.

TabStops

TabStops Collection
Read/write

Returns or sets a TabStops collection that represents all the custom tab stops for the specified paragraphs.

WidowControl

Read/write Long

True if the first and last lines in the specified paragraph remain on the same page as the rest of the paragraph when Word repaginates the document. Can be True, False or wdUndefined.

WordWrap

Read/write Long

True if Microsoft Word wraps Latin text in the middle of a word in the specified paragraphs or text frames. This property returns wdUndefined if its set to True for only some of the specified paragraphs or text frames.

Enumeration WdParagraphAlignment

Enumeration WdParagraphAlignment defines paragraph alignment type.

Constant Value
wdAlignParagraphCenter 1
wdAlignParagraphDistribute 4
wdAlignParagraphJustify 3
wdAlignParagraphJustifyHi 7
wdAlignParagraphJustifyLow 8

Enumeration WdBaselineAlignment

Enumeration WdBaselineAlignment defines vertical placement of the font relative to base line.

Constant Value
wdBaselineAlignAuto 4
wdBaselineAlignBaseline 2
wdBaselineAlignCenter 1
wdBaselineAlignFarEast50 3
wdBaselineAlignTop 0

Enumeration WdLineSpacing

Enumeration WdLineSpacing defines line spacing or rule of its calculation.

Constant Value
wdLineSpace1pt5 1
wdLineSpaceAtLeast 3
wdLineSpaceDouble 2
wdLineSpaceExactly 4
wdLineSpaceMultiple 5
wdLineSpaceSingle 0

Enumeration WdOutlineLevel

Enumeration WdOutlineLevel defines outline level.

Constant Value
wdOutlineLevel1 1
wdOutlineLevel2 2
wdOutlineLevel3 3
wdOutlineLevel4 4
wdOutlineLevel5 5
wdOutlineLevel6 6
wdOutlineLevel7 7
wdOutlineLevel8 8
wdOutlineLevel9 9
wdOutlineLevelBodyText 10

ParagraphFormat

ParagraphFormat object methods are described in the following table.

Method

Description

CloseUp

Removes any spacing before the specified paragraphs.

IndentCharWidth(Count)

Indents one or more paragraphs by a specified number of characters.
Count       Required Integer. The number of characters by which the specified paragraphs are to be indented.

Using this method is equivalent to clicking the Increase Indent button on the Formatting toolbar.

IndentFirstLineCharWidth (Count)

Indents the first line of one or more paragraphs by a specified number of characters.
Count    Required Integer. The number of characters by which the first line of each specified paragraph is to be indented.

OpenOrCloseUp

If spacing before the specified paragraphs is 0 (zero), this method sets spacing to 12 points. If spacing before the paragraphs is greater than 0 (zero), this method sets spacing to 0 (zero).

OpenUp

Sets spacing before the specified paragraphs to 12 points.

Reset

Removes manual paragraph formatting (formatting not applied using a style). For example, if you manually right align a paragraph and the underlying style has a different alignment, the Reset method changes the alignment to match the formatting of the underlying style.

Space1

Single-spaces the specified paragraphs. The exact spacing is determined by the font size of the largest characters in each paragraph.

Space15

Formats the specified paragraphs with 1.5-line spacing. The exact spacing is determined by adding 6 points to the font size of the largest character in each paragraph.

Space2

Double-spaces the specified paragraphs. The exact spacing is determined by adding 12 points to the font size of the largest character in each paragraph.

TabHangingIndent(Count)

Sets a hanging indent to a specified number of tab stops. Can be used to remove tab stops from a hanging indent if the value of Count is a negative number.
Count    Required Integer. The number of tab stops to indent (if positive) or the number of tab stops to remove from the indent (if negative).

TabIndent(Count)

Sets the left indent for the specified paragraphs to a specified number of tab stops. Can also be used to remove the indent if the value of Count is a negative number.
Count    Required Integer. The number of tab stops to indent (if positive) or the number of tab stops to remove from the indent (if negative).

 


Etudes for Microsoft Word Programmers. Appendix. Object ParagraphFormat.


Unless otherwise noted, all materials on this site are
2000-2009 Evgeny Akhundzhanov, All Rights Reserved Worldwide
Microsoft is in no way affiliated with, nor offers endorsement of, this site.
www.transcriber.ru | E-mail the Author