2017-10-16 55 views
0

我在尋找一個腳本,可以每天覆制一個標籤或表單,並用今天的日期重命名該表單。每日重複表單

我相信這是可能的,但我無法在任何地方找到答案。
我到目前爲止的腳本是在下面,但它不起作用,我不能得到正確的週期,使其工作。

function CreateNewPulseSheet() { 

    // The code below makes a duplicate of the active sheet 
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("master do not use"); 
    SpreadsheetApp .getSheetByName().duplicateActiveSheet(); 

    // The code below will rename the active sheet to a date based on cell M1 of the source spreadsheet 

var myValue = SpreadsheetApp.getActiveSheet().getRange("M1").getDisplayValue(); 
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(myValue); 

} 
+0

[Google腳本複製和重命名工作表和名稱基於單元格引用]的可能重複(https://stackoverflow.com/questions/23472440/google-script-to-copy-and-rename-a -sheet-and-name-is-based-a-cell-reference) –

回答

0

這與上面Rubén評論中提到的問題幾乎相同。但要回答這段代碼出了什麼問題,您複製表單的行是問題所在。在SpreadsheetApp後面有一個空格,然後調用getSheetByName(),它將返回一個Sheet對象。 Sheet對象沒有方法duplicateActiveSheet()。 你想要做的是這樣的:

function CreateNewPulseSheet() { 
    // The code below makes a duplicate of the active sheet 
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName("master do not use").activate(); //getSheetByName returns a Sheet, but doesn't set it as active 
    SpreadsheetApp.getActiveSpreadsheet.duplicateActiveSheet(); /Duplicate makes a copy and sets it as the active sheet 

    // The code below will rename the active sheet to a date based on cell M1 of the source spreadsheet 
    var myValue = SpreadsheetApp.getActiveSheet().getRange("M1").getDisplayValue(); 
    SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(myValue); 
} 

我拿出表變量,因爲你永遠不聲明之後引用它。

+0

謝謝你,我已經使用你的編輯,我完美的工作, –