RemovePageByID Method

Removes the page with the specified ID (the ID property) from the page collection of the document. Returns the number of pages, remaining in the document after the operation.

Applies to: Document object

Syntax

[[Let] countRet =] object.RemovePageByID ( pageID )

The RemovePageByID method syntax has these parts:

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

Required. An expression that returns a Long value. Indicates the ID (the ID property) of the page to be removed in the page collection of the document.

countRet Optional. A Long type variable.

Remarks

If there is no page with the specified ID (the ID property) in the document, the RemovePageByID method doesn't delete the page and returns the number of pages in the document. 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 attempts to remove the page with the ID specified by the user by using the RemovePageByID method. Then in analyses the number of the pages in the document, and displays a message saying whether the page was removed.

' Declare variables
Dim pageID As Long
Dim count As Long


' The user inputs the ID of the page
' to be deleted
Let pageID = InputBox( "Enter ID of page to delete:", "Delete page by ID" )

' Remember the number of pages in the document 
' before the attempt to remove the page
Let count = thisDoc.PagesNum()

' Remove the page with the specified ID
If count = thisDoc.RemovePageByID( pageID ) Then
    ' If the number of pages hasn't changed, 
    ' display a message that the page wasn't deleted
    MsgBox( "Page has been deleted!" )
Else
    ' If the number of pages hast changed, 
    ' display a message that the page has been  deleted
    MsgBox( "Page with ID = " & pageID & " has been deleted!" )
End If

 

See Also

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