Web Applications Stack Exchange is a question and answer site for power users of web applications. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've used this script to create a Google Document (like word document) with Google Spreadsheet. But, when I do so, the new text document created from a template is placed in the default chosen folder. And, after that, I have to go to that folder, find the new document and open it.

The million dollar question is: how could I make the newly created text document to automatically open? I think that if it wasn't a Google text Document but a spreadsheet I should use SpreadsheetApp.getActive(). Is there a document equivalent of .getActive()?.

share|improve this question
up vote 1 down vote accepted

I've found no direct way of opening a created document through Google Apps Script (GAS), via GAS. There's however an indirect way, which is presented below. It uses an Anchor element to show a pre-formatted hyperlink.


// global
var ss = SpreadsheetApp.getActive();

function onOpen() {
  var menu = [{name: "Create Document", functionName: "createDoc"}];
  ss.addMenu("Extra", menu);

function createDoc() {
  var sh = ss.getActiveSheet(), aRow = sh.getActiveCell().getRowIndex();
  var title = sh.getRange(aRow, 1).getValue(), docDate = new Date(); 
  var docTitle = title + "-" + docDate, doc = DocumentApp.create(docTitle);
  var url = doc.getUrl();

  // create app and panel
  var app = UiApp.createApplication().setTitle("Open Google Document")
  var vPanel = app.createVerticalPanel()
    .add(app.createAnchor(docTitle, url));

  // add to app


enter image description here


This piece of code creates a new menu entry called "Extra" upon opening of the file. The selection "Create Document" will create (in the back gound) a Google Document and displays a panel with a hyperlink to open the document.


I've created an example file for you: How To Open Document

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.