The Paragraph Object

     

The Paragraph Object

From characters , words, and sentences, you make the next logical text leap: paragraphs. A Paragraph object is a member of the Paragraphs collection, which represents all the paragraphs in the specified Document , Range , or Selection . As with the other text objects, you use an index number with the Paragraphs object to specify an individual paragraph.

Some Useful Paragraph Object Properties

Word's various paragraph formatting options are well-represented in the large set of properties available for the Paragraph object. Here are a few useful ones:

Paragraph .LeftIndent ” Returns or sets the left indent (in points) of the specified Paragraph .

Paragraph .LineSpacing ” Returns or sets the line spacing setting (in points) for the specified Paragraph .

Paragraph .RightIndent ” Returns or sets the right indent (in points) for the specified Paragraph .

Paragraph .SpaceAfter ” Returns or sets the spacing (in points) after the specified Paragraph .

Paragraph .SpaceBefore ” Returns or sets the spacing (in points) before the specified Paragraph .

Paragraph .Style ” Returns or sets the style of the specified Paragraph . Word has a huge number of constants that represent its predefined styles. For example, to set the Heading 1 style, you would use the wdStyleHeading1 constant. To see the other constants, search for wdBuiltInStyle in the Object Browser.

The following procedure fragment applies several properties to the active paragraph (recall that the InchesToPoints function converts values expressed in inches to the equivalent value expressed in points):

 With Selection.Range     .LeftIndent=InchesToPoints(1)     .LineSpacing=12     .SpaceAfter=6     .Style=wdStyleNormal End With 

Some Useful Paragraph Object Methods

To finish our look at the Paragraph object, here are a few methods you can wield in your code:

Paragraph .Indent ” Indents the specified Paragraph to the next tab stop.

Paragraph .Outdent ” Outdents the Paragraph to the previous tab stop.

Paragraph .Space1 ” Sets the specified Paragraph to single- spaced .

Paragraph .Space15 ” Sets the specified Paragraph to 1.5-line spacing.

Paragraph .Space2 ” Sets the specified Paragraph to double-spaced.

The Absolute Minimum

This chapter took you on a tour of VBA in Word. You learned more about Word's Application object, including a few useful properties and methods. From there, we went through a number of Word-specific objects, including the Document , Range , Selection , Characters , Words , Sentences , and Paragraph objects.

Here's a list of chapters where you'll find related information:

  • For a general discussion of VBA objects, see Chapter 5, "Working with Objects."

  • I show you how to use MsgBox and other interaction functions in Chapter 12, "Interacting with the User."

  • The MakeBackup procedure should probably check to see whether there is a disk in drive A for running the SaveAs method. I show you how to account for this type of error in Chapter 15, "Debugging VBA Procedures."




Absolute Beginner's Guide to VBA
Absolute Beginners Guide to VBA
ISBN: 0789730766
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net