PageSetup (object)

<< Click to Display Table of Contents >>

PageSetup (object)

Access paths:

Application à Workbooks à Item à Sheets à Item à PageSetup

Application à Workbooks à ActiveSheet à PageSetup

Application à ActiveWorkbook à ActiveSheet à PageSetup

Application à ActiveSheet à PageSetup

 1  Description

The PageSetup object contains the page settings of the Sheet object to which it belongs. You can use it to determine and change the paper size, page size and margins as well as the print direction of a single worksheet.

 2  Access to the object

Each worksheet in a document has exactly one instance of the PageSetup object. It is accessed through Sheet.PageSetup:

' Set the left margin of the active sheet to 2cm

pm.ActiveSheet.PageSetup.LeftMargin = pm.CentimetersToPoints(2)

Note: You can define different page settings for each individual worksheet in a document.

 3  Properties, objects, collections and methods

Properties:

LeftMargin

RightMargin

TopMargin

BottomMargin

HeaderMargin

FooterMargin

PageHeight

PageWidth

Orientation

PaperSize

PrintComments

CenterHorizontally

CenterVertically

Zoom

FirstPageNumber

PrintGridlines

PrintHeadings

Order

PrintArea

PrintTitleRows

PrintTitleColumns

 

Objects:

Application Application

Parent Sheet

LeftMargin (property)

Data type: Single

Gets or sets the left page margin of the worksheet in points (1 point corresponds to 1/72 inches).

RightMargin (property)

Data type: Single

Gets or sets the right page margin of the worksheet in points (1 point corresponds to 1/72 inches).

TopMargin (property)

Data type: Single

Gets or sets the top page margin of the worksheet in points (1 point corresponds to 1/72 inches).

BottomMargin (property)

Data type: Single

Gets or sets the bottom page margin of the worksheet in points (1 point corresponds to 1/72 inches).

HeaderMargin (property)

Data type: Single

Gets or sets the distance between the header and the top edge of the sheet in points (1 point corresponds to 1/72 inches).

FooterMargin (property)

Data type: Single

Gets or sets the distance between the footer and the bottom edge of the sheet in points (1 point corresponds to 1/72 inches).

PageHeight (property)

Data type: Single

Gets or sets the page height of the worksheet in points (1 point corresponds to 1/72 inches).

If you set this property, the PaperSize property (see below) will be automatically changed to a suitable paper format.

PageWidth (property)

Data type: Single

Gets or sets the page width of the worksheet in points (1 point corresponds to 1/72 inches).

If you set this property, the PaperSize property (see below) will be automatically changed to a suitable paper format.

Orientation (property)

Data type: Long (SmoOrientation)

Gets or sets the page orientation of the worksheet. The following constants are allowed:

smoOrientLandscape   = 0 ' Landscape

smoOrientPortrait    = 1 ' Portrait

PaperSize (property)

Data type: Long (SmoPaperSize)

Gets or sets the page size of the worksheet. The following constants are allowed:

smoPaperCustom              = -1

smoPaperLetter              = 1

smoPaperLetterSmall         = 2

smoPaperTabloid             = 3

smoPaperLedger              = 4

smoPaperLegal               = 5

smoPaperStatement           = 6

smoPaperExecutive           = 7

smoPaperA3                  = 8

smoPaperA4                  = 9

smoPaperA4Small             = 10

smoPaperA5                  = 11

smoPaperB4                  = 12

smoPaperB5                  = 13

smoPaperFolio               = 14

smoPaperQuarto              = 15

smoPaper10x14               = 16

smoPaper11x17               = 17

smoPaperNote                = 18

smoPaperEnvelope9           = 19

smoPaperEnvelope10          = 20

smoPaperEnvelope11          = 21

smoPaperEnvelope12          = 22

smoPaperEnvelope14          = 23

smoPaperCSheet              = 24

smoPaperDSheet              = 25

smoPaperESheet              = 26

smoPaperEnvelopeDL          = 27

smoPaperEnvelopeC5          = 28

smoPaperEnvelopeC3          = 29

smoPaperEnvelopeC4          = 30

smoPaperEnvelopeC6          = 31

smoPaperEnvelopeC65         = 32

smoPaperEnvelopeB4          = 33

smoPaperEnvelopeB5          = 34

smoPaperEnvelopeB6          = 35

smoPaperEnvelopeItaly       = 36

smoPaperEnvelopeMonarch     = 37

smoPaperEnvelopePersonal    = 38

smoPaperFanfoldUS           = 39

smoPaperFanfoldStdGerman    = 40

smoPaperFanfoldLegalGerman  = 41

PrintComments

Data type: Long (PmPrintLocation)

Gets or sets the setting whether comments should be printed in the worksheet. Corresponds to the setting "Comments" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup. The following constants are allowed:

pmPrintNoComments   = 0 ' Don't print comments

pmPrintInPlace      = 1 ' Print comments

CenterHorizontally

Data type: Boolean

Gets or sets the setting whether the worksheet should be centered horizontally when printing. Corresponds to the setting "Center horizontally" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

CenterVertically

Data type: Boolean

Gets or sets the setting whether the worksheet should be centered vertically when printing. Corresponds to the setting "Center vertically" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

Zoom

Data type: Long

Gets or sets the zoom level at which the worksheet should be printed. Corresponds to the setting "Scaling" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

FirstPageNumber

Data type: Long

Gets or sets the page number for the first page when printing. You can pass the value pmAutomatic to give the first page the page number 1. Corresponds to the setting "Page number" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

PrintGridlines

Data type: Boolean

Gets or sets the setting whether the grid lines of the worksheet should be printed. Corresponds to the setting "Grid" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

PrintHeadings

Data type: Boolean

Gets or sets the setting whether the row and column headers of the worksheet should be printed. Corresponds to the setting "Row and column headers" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

Order

Data type: Long (PmOrder)

Gets or sets the printing order for multi-page worksheets. The possible values are:

pmOverThenDown   = 0 ' From left to right

pmDownThenOver   = 1 ' From top to bottom

Corresponds to the setting "Print order" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

PrintArea

Data type: String

Gets or sets the print range of the worksheet, analogous to the ribbon command File | Print group | Define print range.

If an empty string is returned, no print area is currently defined. If you pass an empty string, the existing print area will be removed.

PrintTitleRows

Data type: String

Gets or sets the repeated rows of the worksheet, analogous to the setting "Repeated rows" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

Example:

' Repeat the rows 2 to 5 of the active worksheet

pm.ActiveSheet.PageSetup.PrintTitleRows = "2:5"

PrintTitleColumns

Data type: String

Gets or sets the repeat rows of the worksheet, analogous to the setting "Repeated columns" on the Options tab in the dialog box of the ribbon command File | Print group | Page setup.

Example:

' Repeat the columns A to C of the active worksheet

pm.ActiveSheet.PageSetup.PrintTitleColumns = "A:C"

Application (pointer to object)

Data type: Object

Returns the Application object.

Parent (pointer to object)

Data type: Object

Returns the parent object, i.e. an object of the type Sheet.