[英]how to run onEdit funtion with a button
my onEdit function does not work when there is frequent disconnection of internet. 互联网经常断开连接时,我的onEdit函数不起作用。 i want to assign it to a button so that when there is internet available i will press the button and does it work. 我想将其分配给一个按钮,以便当有可用的互联网时,我将按下该按钮并使其工作。 i also tried change the function name but still does not perform its work with a button. 我也尝试过更改函数名称,但仍然无法通过按钮执行其工作。 how ever it works without button the code is 没有按钮,代码如何工作
function onEdit(evt) {
try {
if( evt.range.getSheet().getName() === "invoice" ) {
// Qty is in column F
if( ( evt.range.getRow() > 7 ) && ( evt.range.getRow() < 29 ) && (
evt.range.getColumn() === 6 ) ) {
var sheet = evt.source.getSheetByName("stock");
var range = sheet.getDataRange();
var stock = range.getValues();
for( var i=0; i<stock.length; i++ ) {
// Compare to column B
if( stock[i][0] === evt.range.offset(0,-4,1,1).getValue() ) {
range.offset(i,2,1,1).setValue(evt.value);
return
}
}
//this alert no need if this function assigned to a button
SpreadsheetApp.getUi().alert("Item
<"+evt.range.offset(0,-4,1,1).getValue()+"> not found!");
}
}
}
catch(err) {
Logger.log(err);
}
}
You can create a custom menu to manually run your code. 您可以创建一个自定义菜单来手动运行您的代码。 In this example, assume that your onEdit()
function is now called doSomething()
. 在此示例中,假定您的onEdit()
函数现在称为doSomething()
。
// The onOpen function is executed automatically every time a Spreadsheet is loaded
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Do Something", functionName: "doSomething"});
ss.addMenu("Custom Menu", menuEntries);
}
You're going to have to rewrite your script so that it does not rely on evt
, as that will no longer be available. 您将不得不重写脚本,使其不依赖evt
,因为它将不再可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.