PageNumbers 方法(Word)PageNumbers.Add method (Word)

返回一个PageNumber对象,该对象代表添加到节中的页眉或页脚中的页码。Returns a PageNumber object that represents page numbers added to a header or footer in a section.

语法Syntax

表达式AddPageNumberAlignmentFirstPageexpression.Add (PageNumberAlignment, FirstPage)

expression 是必需的。expression Required. 一个代表**PageNumbers** 对象的变量。A variable that represents a PageNumbers object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
PageNumberAlignmentPageNumberAlignment 可选Optional VariantVariant 可以是任何WdPageNumberAlignment常量。Can be any WdPageNumberAlignment constant.
FirstPageFirstPage 可选Optional VariantVariant 以使第一页页眉和首页页脚与文档中所有后续页面的页眉和页脚不同。False to make the first-page header and the first-page footer different from the headers and footers on all subsequent pages in the document. 如果 FirstPage 设置为False,则页面编号不会添加到第一页。If FirstPage is set to False, a page number isn't added to the first page. 如果省略此参数,则设置由DifferentFirstPageHeaderFooter属性控制。If this argument is omitted, the setting is controlled by the DifferentFirstPageHeaderFooter property.

备注Remarks

如果将 HeaderFooter 对象的 LinkToPrevious 属性设置为 True,则文档中各节的页码都将连续编号。If the LinkToPrevious property for the HeaderFooter object is set to True, the page numbers will continue sequentially from one section to next throughout the document.

示例Example

本示例为活动文档第一节的主页脚添加页码。This example adds a page number to the primary footer in the first section of the active document.

With ActiveDocument.Sections(1) 
 .Footers(wdHeaderFooterPrimary).PageNumbers.Add _ 
 PageNumberAlignment:=wdAlignPageNumberLeft, _ 
 FirstPage:=True 
End With

本示例在活动文档的页眉中创建页码并进行格式设置。This example creates and formats page numbers in the header for the active document.

Set myPgNum = ActiveDocument.Sections(1) _ 
 .Headers(wdHeaderFooterPrimary) _ 
 .PageNumbers.Add(PageNumberAlignment:= _ 
 wdAlignPageNumberCenter, FirstPage:= True) 
myPgNum.Select 
With Selection.Range 
 .Italic = True 
 .Bold = True 
End With

另请参阅See also

PageNumbers 集合对象PageNumbers Collection Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.