RemovePage Method

Removes the page with the specified index from the page collection of the document. Returns the number of pages, remaining in the collection after the operation.

Applies to: Document object

Syntax

[[Let] countRet =] object.RemovePage ( index )

The RemovePage method syntax has these parts:

Part Description
object Required. An expression, that returns an instance of the Document object.
index

Required. An expression that returns a Long value. Indicates the index of the page to be removed in the page collection of the document.

countRet Optional. A Long type variable.

Remarks

If index is less than 1, or greater than the number of pages in the document, the RemovePage method doesn't remove the page. When a page is removed, the remaining pages are re-indexed - that is, the index of every page following the removed one is decreased by 1. Use the PagesNum method to find out the number of the pages in the document.

You can't remove all the pages - at least one page must exist in the document. An attempt to delete the last page will have no effect. Also, you can't remove the page if its script or the script of one of its shapes is being executed at the moment.

Example

This example contains a document-level script. The program removes all pages that don't have shapes on them. Pages are removed with the RemovePage method.

' Loop through all pages of the document
For i=thisDoc.PagesNum() To 1 Step -1

    ' If there are no shapes on the page
    ' delete page
    If thisDoc.Page(i).ShapesNum() = 0 Then
        thisDoc.RemovePage(i)
    End If

Next i

 

See Also

AddPage method, FindPage method, Page method, PageByID method, PagesNum method, RemovePageByID method, ReorderPage method, ReorderPageByID method, Page object