class DocumentApp method .getActiveDocument()

DocumentApp is the Apps Script service.

.getActiveDocument() is the method name you will see after a dot in your code.

What it does

Returns the Google Doc the user currently has open.

Why it's used

  • Edit the Google Doc the user has open right now.
  • Bound doc scripts use this like getActiveSpreadsheet for sheets.

Common errors

  • Forgetting parentheses on getActiveDocument. Write DocumentApp.getActiveDocument(), not DocumentApp.getActiveDocument or getActiveDocument by itself.
  • Skipping dots between chained calls. Each step needs a dot, like DocumentApp.getActiveDocument().getBody().getActiveDocument().
  • Adding spaces where they do not belong. Write DocumentApp.getActiveDocument(), not DocumentApp .getActiveDocument(), DocumentApp.getActiveDocument (), or DocumentApp . getActiveDocument().
  • Wrong capitalization. Use DocumentApp and getActiveDocument, not documentapp or getactivedocument.

Snippets using this method

Explore

Related methods

  • .openById()

    Opens an existing Google Doc by its file ID.

  • .create()

    Creates a new blank Google Doc.

  • .getBody()

    Returns the main body section of the document for editing.

  • .getText()

    Reads the plain text content of a document element.

  • .setText()

    Replaces the text content of a document element.

Better Sheets tutorials

Build a Better ChatGPT Prompt Builder

Build a Better ChatGPT Prompt Builder

In this sheet review I take another YouTuber's ChatGPT prompt builder th...

Related blog posts

Written guides about DocumentApp.getActiveDocument().

Browse the blog