Class Selection

  • The Selection object represents the current selection in an active presentation.

  • You can get the currently active page, selected page elements, selected pages in the filmstrip, selected table cells, or selected text range using methods likegetCurrentPage(),getPageElementRange(),getPageRange(),getTableCellRange(), andgetTextRange().

  • The type of the current selection can be determined using thegetSelectionType() method.

Selection

The user's selection in the active presentation.

constselection=SlidesApp.getActivePresentation().getSelection();constcurrentPage=selection.getCurrentPage();constselectionType=selection.getSelectionType();

Methods

MethodReturn typeBrief description
getCurrentPage()Page|nullReturns the currently activePage ornull if there is no active page.
getPageElementRange()PageElementRange|nullReturns thePageElementRange collection ofPageElement instances that areselected ornull if there are noPageElement instances selected.
getPageRange()PageRange|nullReturns thePageRange a collection ofPage instances in the flimstrip that areselected ornull if the selection is not of typeSelectionType.PAGE.
getSelectionType()SelectionTypeReturns theSelectionType.
getTableCellRange()TableCellRange|nullReturns theTableCellRange collection ofTableCell instances that are selectedornull if there are noTableCell instances selected.
getTextRange()TextRange|nullReturns theTextRange that is selected ornull if the selection is not of typeSelectionType.TEXT.

Detailed documentation

getCurrentPage()

Returns the currently activePage ornull if there is no active page.

constselection=SlidesApp.getActivePresentation().getSelection();constcurrentPage=selection.getCurrentPage();if(currentPage!=null){Logger.log(`Selected current active page ID:${currentPage.getObjectId()}`);}

Return

Page|null

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getPageElementRange()

Returns thePageElementRange collection ofPageElement instances that areselected ornull if there are noPageElement instances selected.

constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.PAGE_ELEMENT){constcurrentPage=selection.getCurrentPage();constpageElements=selection.getPageElementRange().getPageElements();Logger.log(`Number of page elements selected:${pageElements.length}`);}

Return

PageElementRange|null

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getPageRange()

Returns thePageRange a collection ofPage instances in the flimstrip that areselected ornull if the selection is not of typeSelectionType.PAGE.

constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.PAGE){constpageRange=selection.getPageRange();Logger.log(`Number of pages in the flimstrip selected:${pageRange.getPages().length}`,);}

Return

PageRange|null

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getSelectionType()

Returns theSelectionType.

constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.CURRENT_PAGE){constcurrentPage=selection.getCurrentPage();Logger.log(`Selected current active page ID:${currentPage.getObjectId()}`);}

Return

SelectionType

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getTableCellRange()

Returns theTableCellRange collection ofTableCell instances that are selectedornull if there are noTableCell instances selected.

constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.TABLE_CELL){constcurrentPage=selection.getCurrentPage();consttableCells=selection.getTableCellRange().getTableCells();consttable=tableCells[0].getParentTable();Logger.log(`Number of table cells selected:${tableCells.length}`);}

Return

TableCellRange|null

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getTextRange()

Returns theTextRange that is selected ornull if the selection is not of typeSelectionType.TEXT.

TheTextRange represents two scenarios:

1. Range of text selected. For example if a shape has text "Hello", and "He" is selected,the returned range hasTextRange.getStartIndex() = 0, andTextRange.getEndIndex() =2.

2. Cursor position. For example if a shape has text "Hello", and cursor is after "H",("H|ello"), the returned range hasTextRange.getStartIndex() = 1 andTextRange.getEndIndex() = 1.

constselection=SlidesApp.getActivePresentation().getSelection();constselectionType=selection.getSelectionType();if(selectionType===SlidesApp.SelectionType.TEXT){constcurrentPage=selection.getCurrentPage();constpageElement=selection.getPageElementRange().getPageElements()[0];consttextRange=selection.getTextRange();Logger.log(`Text selected:${textRange.asString()}`);}

Return

TextRange|null

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.