Each page, or Page object, is a member of the Document.Pages collection for the document in which it appears. The pages in a Document.Pages collection appear in the order in which they appear in that document — for example, the fifth page in the active document is ActiveDocument.Pages.Item(5). If pages are added, reordered, or deleted, the affected Pages collection is immediately updated to reflect the new page order of that document.
ActiveDocument.Pages.Item(5)
Corel DESIGNER and CorelDRAW providea number of properties, methods, and events for working with pages, the most useful of which are listed in the following table.
For detailed information on any property, method, or event, see the API documentation.
For more information on page-related activities, see the following subtopics:
The methods for creating pages belong to the Document class.
Both the Document.AddPages method and the Document.AddPagesEx method add the specified number of pages to the end of a document. The difference between these methods is that AddPages uses the default page size, while AddPagesEx uses a specified size.
Similarly, both the Document.InsertPages method and the Document.InsertPagesEx method insert the specified number of pages at the specified location in a document. The difference between these methods is that InsertPages uses the default page size, while InsertPagesEx uses a specified size.
As an example, the following VBA code uses the AddPages method to add three default-sized pages to the end of the document:
Public Function AddSomeSimplePages() as Page Set AddSomeSimplePages = ActiveDocument.AddPages(3) End Function
The following VBA example uses the AddPagesEx method to add to the end of the document three pages that are 8.5 inches wide by 11 inches high:
Public Function AddSomeSpecifiedPages() as Page Dim doc as Document Set doc = ActiveDocument doc.Unit = cdrInch Set AddSomeSpecifiedPages = doc.AddPagesEx(3, 8.5, 11) End Function
The preceding examples return the first page that was added; all other added pages follow this page. You can therefore reference any of the added pages by incrementing the Index property of the returned page:
Dim firstNewPage As Page, secondNewPage As Page Set firstNewPage = AddSomeSimplePages Set secondNewPage = ActiveDocument.Pages(firstNewPage.Index + 1)
If you want, you can use event handlers to respond to events that are triggered by creating a page:
Each page is a member of the Document.Pages collection for the document in which it appears. The pages in a Document.Pages collection appear in the order in which they appear in that document — for example, the fifth page in the active document is ActiveDocument.Pages.Item(5). If pages are added, reordered, or deleted, the affected Pages collection is immediately updated to reflect the new page order of that document.
You can access the active page of the active document by using the Application.ActivePage property (or ActiveDocument.ActivePage, or simply ActivePage). A reference to the active page in the active document, of type Page, is returned.
ActiveDocument.ActivePage
ActivePage
Dim pg As Page Set pg = ActivePage
You can access the active page of a document, regardless of whether that document is active, by using ActivePage property for that document:
Public Function getDocsActivePage(doc As Document) As Page Set getDocsActivePage = doc.ActivePage End Function
You can switch pages by finding the desired page and then invoking its Activate method. The following VBA code activates page 3 in a document:
ActiveDocument.Pages(3).Activate
If you want, you can use event handlers to respond to events that are triggered by activating a page:
You can also use event handlers to respond to events that are triggered by deactivating a page:
A page can be moved to another location in a document by using its MoveTo method. The following VBA code moves page 2 to the position of page 4:
ActiveDocument.Pages(2).MoveTo 4
Activating a page in an inactive document does not activate that document. To activate a document, you must use its Activate method (see Activating documents).
You can specify the size and orientation of pages, specifying the default page size, and use defined page sizes.
Specifying the size and orientation of pages
You can size a page by using its SetSize method, which applies two size values (width and height) to the page.
The following VBA code changes the size of the active page in the active document to A4:
ActiveDocument.Unit = cdrMillimeter ActivePage.SetSize 210, 297 ActivePage.Orientation = cdrLandscape
For the SetSize method, the first number is always the page width and the second number is always the page height. Reversing the two numbers switches the orientation of the page.
Specifying the default page size
The default page size for a document is determined by the value of the item that has an index of 0 in the Document.Pages collection. You can specify the default page size by changing the value of this item:
Dim doc As Document Set doc = ActiveDocument doc.Unit = cdrMillimeter doc.Pages(0).SetSize 297, 210
Alternatively, you can use the Document.MasterPage property to specify the default page size:
Dim doc As Document Set doc = ActiveDocument doc.Unit = cdrMillimeter doc.MasterPage.SetSize 297, 210
Using defined pages sizes
Page sizes can be defined by either the application or the user. All defined page sizes are stored in the Application.PageSizes collection, and the name of each PageSize object in that collection is defined by its Name property:
Dim pageSizeName As String pageSizeName = Application.PageSizes(3).Name
Page sizes can be specified by name. For example, the following VBA code gets the PageSize object named "Business Card":
Dim thisSize As PageSize Set thisSize = Application.PageSizes("Business Card")
You can get the actual dimensions of a PageSize object by using its Width and Height properties. The following VBA code retrieves the width and height (in millimeters) of the third PageSize object:
Dim pageWidth As Double, pageHeight As Double Application.Unit = cdrMillimeter pageWidth = Application.PageSizes(3).Width pageHeight = Application.PageSizes(3).Height
Although each PageSize object provides a Delete method, this method can be used only on user-defined page sizes. You can determine whether a PageSize object is user-defined by testing its BuiltIn Boolean property:
Public Sub deletePageSize(thisSize As PageSize) If Not thisSize.BuiltIn Then thisSize.Delete End Sub
You can specify a particular unit of measurement for a page size by setting the units for the document before getting its width and height.
You can modify a page regardless of whether it is active.
By explicitly referencing the page that you want to modify, you can make those changes without activating the page. The following VBA code deletes all shapes on page 3 of the active document without activating that page:
Public Sub DeleteShapesFromPage3() Dim doc As Document Set doc = ActiveDocument doc.Pages(3).Shapes.All.Delete End Sub
You can delete a page by using its Delete method, as in the following VBA example:
ActivePage.Delete
The Page.Delete method deletes all shapes on that page, deletes the page from the Pages collection for that document, and then updates that collection to reflect the change.
If you want to delete more than one page, you must use the Delete method for each unwanted page. However, you cannot delete all pages in a document. You can avoid trying to delete the last remaining page in a document by using the following VBA code:
If ActiveDocument.Pages.Count > 1 Then ActivePage.Delete
If you want, you can use event handlers to respond to events that are triggered by deleting a page: