Batch copying/renaming in Google Docs

Posted on

Batch copying/renaming in Google Docs – Whether you’re just starting out with Google Sheets or are a seasoned pro, sooner or later one of your formulas will give you a formula or script parse error message rather than the result you want. However, every Formula user, irrespective of whether it’s a beginner or expert, has invariably come across a formula parse error in Google Sheets at least once in their life (and if you haven’t. you soon will). It can be frustrating, especially if it’s a longer formula where the formula parse error may not be obvious. In this article, we will talk about some common script or formula parse errors in Google Sheets, like Batch copying/renaming in Google Docs, and how to fix it.

I need to copy and rename a base form (a spreadsheet) to several other forms in Google Docs. Imagine I have the following form:

  • My Base Form – @name (@course)

After running the script or whatever, I will end up with those forms:

  • My Form Copy – John Doe (Computer Science)
  • My Form Copy 2 – Donald (Arts)
  • My Form Copy 15 – Andrea (Music)

Any idea on how can I do that?

Answer :

After some research, I figured it myself. Here is my solution if someone faces the same problem and needs a script for that:


function makeForms() {
  // Google Spreadsheet ID
  var BASE_FORM_ID = "0AlDgVsiNXDhjdFlRTFVBeG5rNmprb3kHNxd1ItSFE";

  // object that holds the information 
  var aNames = [     
    {name: "Prof. Fernando", course: "Course name"},
    {name: "Prof. Rafael", course: "Course name"}

  // creation of variables
  var aSpreadsheet, aNewForm, aCurrentName = "";
  var aBaseForm = DocsList.getFileById(BASE_FORM_ID);

  // iterate over the names
  for(var i = 0; iLen = aNames.length; i < iLen; i++) {
    // set name
    aCurrentName = aNames[i].course+" ("+aNames[i].name+")";

    // make copy
    aNewForm = aBaseForm.makeCopy("Evaluation for " + aCurrentName);  

    // open spreadsheet and retrieve ID
    aSpreadsheet = SpreadsheetApp.openById(aNewForm.getId());

    // log the Url's 
    Logger.log(aCurrentName + "  "+aSpreadsheet.getFormUrl());


Leave a Reply

Your email address will not be published. Required fields are marked *