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:

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()