ParagraphFormat 对象

         
多种对象
ParagraphFormat
多种对象

代表段落的所有格式。

使用 ParagraphFormat 对象

使用 Format 属性可返回一个或多个段落的 ParagraphFormat 对象。ParagraphFormat 属性返回所选内容、区域、样式、Find 对象或 Replacement 对象的 ParagraphFormat 对象。下列示例将活动文档中的第三段居中。

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

下列示例查找所选内容之后的下一个两倍行距的段落。

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

说明

可以使用 Visual Basic 的 New 关键词新建单独的 ParagraphFormat 对象。下列示例创建一个 ParagraphFormat 对象,为其设置部分格式属性,然后将其所有属性应用于活动文档中的第一个段落。

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

也可使用 Duplicate 属性生成现有的 ParagraphFormat 对象的单独副本。下列示例复制活动文档中第一段的段落格式,并将格式设置存储于 myDup。该示例将 myDup 的左缩进量更改为 1 英寸,创建新文档,在文档中插入文字,并将 myDup 的段落格式应用于该文字。

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