如何在特定单元格中显示 运行 宏的用户名?

How to display name of the user who ran a macro in a specific cell?

我不太懂技术,很抱歉,所以我问这个但是,有人知道如何在 google 工作表的特定单元格中显示 运行 宏的用户吗?不用担心匿名用户,我希望记录谁运行某个宏以供记录。

您可以通过调用应用程序脚本Session.getActiveUser方法获取当前用户的电子邮件地址,然后使用arguments.callee.name您可以获取使用了哪个宏的名称。

您可以将此代码附加到宏函数的末尾:

  // get email of user that ran the macro
  var user = Session.getActiveUser().getEmail()

  //Set cell to add value to, in this case Sheet2:A1
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2")
  var cell = sheet.getRange(1, 1, 1, 1);

  cell.setValue(user + ' ran macro ' + arguments.callee.name);

您只需要指定将信息写入哪个Cell即可。