我在电子表格中有一张纸上的Google表中有一个宏观的宏。我想编辑脚本,以便它适用于电子表格中的所有表(因此,我不必单独运行每个纸上的宏观宏)。我已经看过有关如何在Excel中执行此操作的文章,但是在Google表中可以吗?
您确定它在其他床单上不起作用吗?记录的宏通常使用活动表而不是命名表。
尽管我迟到了9个月,但这是对您的问题的工作答案,其中一个示例可以清除所有可见纸,使用另一个称为clearactivesheet的函数。如果有人仍在寻找如何做到这一点,这应该给一个想法。
function ClearActiveSheet() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
sheet.getRange('A1').activate();
sheet.clear();
};
function ClearAllVisibleSheets() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
sheets.forEach(function(sheet) {
//You would need to make this the current active sheet, so that you can call the ClearActiveSheet function that works on active sheet
sheet.activate()
// Now since you have this sheet activated, you can call the function to clear the active sheet
ClearActiveSheet();
});
};
从工具 -> scriptseditor-> selectFunction(clearallVisibleSeets)中选择googlespredsheets中的clearallvisibleseets和运行/或debug,您会看到这项工作。
p.s:如果满足您的需求,请记住要投票并友好地接受它作为答案:)。