问题描述
即使运行最简单的Google Apps脚本,我也遇到了麻烦,例如,当我通过将单元格电子表格设置为= pantsHate(Y)运行此脚本时,出现此错误:
错误:您无权调用msgBox
功能pantsHate (pref){
var preference = pref;
switch(首选项){
caseY:
Browser.msgBox(你讨厌裤子。);
休息;
caseN:
Browser.msgBox(你不讨厌裤子。);
休息;
默认值:
Browser.msgBox(你讨厌回答Y或N);
休息;
}
返回pref;
$ / code>
我的最终目标是编写一个小函数来操作日期,具体而言,我需要找到两个日期之间已经过了多少天(闰年,具体日期/月份等都是因素)。这个程序只是一个测试,但我似乎已经做了错误的任何帮助,非常感激!
更新:我在一个新的项目中尝试了这一点,它工作... arg!
更新2:再次用= pantsHate(Y)再次运行,在这个新项目中出现同样的错误...为什么Google,为什么?
自定义函数不能启动消息框(Browser.msgbox())
自定义函数是作为公式的全部或部分输入的函数在从脚本编辑器调用函数的电子表格单元格中。例如,当我通过将单元格电子表格设置为= pantsHate(Y)来运行此脚本时,我得到了这个结果:
= pantsheet(Y)是一个自定义函数,因为您是从电子表格公式调用它,并且它无法启动浏览器。 msgbox()
I'm having trouble running even the simplest Google Apps Scripts, for instance when I run this script by setting a cell my spreadsheet to =pantsHate(Y) I'm getting this error:
error: You do not have permission to call msgBox
function pantsHate(pref) {
var preference = pref;
switch (preference) {
case "Y":
Browser.msgBox("You hate pants.");
break;
case "N":
Browser.msgBox("You do not hate pants.");
break;
default:
Browser.msgBox("You hate answering Y or N");
break;
}
return pref;
}
My end goal is to write a small function to manipulate dates, specifically I need to find exactly how many days have passed between two dates (leap years, specific days / month, etc are all factors). This program was just a test but I seem to be doing something wrong already... any help is greatly appreciated!
Update: I tried this in a new project and it worked... arg!Update 2: Ran it again with =pantsHate("Y") and I got the same error, in this "new" project... why Google, why?
解决方案 Custom functions will do nothing but return a value to a cell in which they reside unless the return an array which may affect contiguous cells.
A custom function cannot initiate a message box(Browser.msgbox())
A custom function is a function entered as all or part of a formula in a spreadsheet cell that calls a function from the script editor. When you state:
=pantsheet(Y) is a custom function because you are calling it from a spreadsheet formula and it cannot initiate a Browser.msgbox()
这篇关于无权在Google Apps脚本中调用msgBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!