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'm trying to create a new spreadsheet once we select the specific function from the custom menu item that's selected. I want the new spreadsheet to be "Sheet" & "Timestamp". Can anyone point me in the right direction?

I have this created but it's giving an error:

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [{name: "Generate Traffic Sheet", functionName: "newSheet"}];

  ss.addMenu("Generate Traffic Sheet", menuEntries);

function newSheet () {
    var ss = SpreadsheetApp.create(name)
    var d = new Date();
    var timeStamp = d.getTime();
share|improve this question
Please add the complete error message to your question. – toscho Jul 27 '13 at 0:14
Hi Jacob, Thanks for the help. I screwed up with fully detailing out my task. I actually don't want a brand new spreadsheet created, rather an additional worksheet (tab) within' the current spreadsheet, with that current spreadsheet labeled as "Traffic Sheet" & Date(). How would that end up looking? Is it just a separate functional rather than SpreadsheetApp.create? – Jeff Jul 29 '13 at 18:18
That would be a different question altogether. Why don't you accept this answer, because it fits the question, and ask a new question. – Jacob Jan Tuinstra Jul 29 '13 at 18:59
up vote 1 down vote accepted

Use the following code to accomplish your task:


function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [{name: "Sheet 1", functionName: "newSheet1"},
                     {name: "Sheet 2", functionName: "newSheet2"}]
  ss.addMenu("Generate Traffic Sheet", menuEntries);

function newSheet1 () {
  var name = "test"; 
  SpreadsheetApp.create(name).getRange("A1").setValue(new Date());

function newSheet2 () {
  var name = "test"; 
  var myDate = Utilities.formatDate(new Date(), "GMT+1", "dd.MM.yyyy");


  • If you would've ran the debugger, then you would've noticed an error message: "name variable doesn't exist". See sheet 1 example.
  • setName() method isn't applicable here for adding data into the other sheet.
  • If you want to access the new spreadsheet, then you need to create that instance as well.
  • the getTime() method will return the amount of millisecond from 01-01-1970 on.
  • I've added two revised code samples, so that you can see the difference

Good luck and happy coding !!

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.