【问题标题】:Creating a form which allows you to pick which sheets you want to run a macro in创建一个表单,允许您选择要在哪些工作表中运行宏
【发布时间】:2019-09-30 08:41:59
【问题描述】:

我有一些系统摘录,其中包含数十张相同格式的工作表。为了更好地呈现每张工作表中的数据,我喜欢为许多(不是全部)工作表创建简单的汇总表。

我创建了一个简单的宏,它将工作表中的关键数据提取到表格中。我想要的是,如果我可以选择要在哪些工作表上运行宏,例如通过在表单上使用复选框。关于如何做到这一点的任何想法?

【问题讨论】:

  • 使宏成为接受作为工作表名称的字符串参数的子例程,然后使工作表名称成为代码中的变量。那么这只是一个使用多选列表框的问题。

标签: google-apps-script google-sheets google-forms


【解决方案1】:

您可以合并onEdit trigger,它会在选择每个复选框时触发。

您可以使用e.range 检索已选中复选框的单元格,然后根据您的需要进行操作。

示例:

function onEdit(e) {
  var checkboxColumnIndex=1: //as a sample
  //if the edited cell is your checkbox column and the box status was changed from unchecked to checked
  if(e.range.getColumn()==checkboxColumnIndex2&&e.range.getValue()==true){
   var checkboxRow=e.range.getRow());
   var sheetIndex=checkBoxRow();
   var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[sheetIndex];
  //do what you wnat with this sheet
  }
}

每次选中复选框时,此功能将自动运行。

【讨论】:

    猜你喜欢
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 2013-06-07
    相关资源
    最近更新 更多