No permission to call msgBox in Google Apps Scripting

こ雲淡風輕ζ 提交于 2019-12-17 06:57:09

问题


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?


回答1:


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:

for instance when I run this script by setting a cell my spreadsheet to =pantsHate(Y) I'm getting this error:

=pantsheet(Y) is a custom function because you are calling it from a spreadsheet formula and it cannot initiate a Browser.msgbox()



来源:https://stackoverflow.com/questions/10506105/no-permission-to-call-msgbox-in-google-apps-scripting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!