0

I'm trying to create a function in google sheets to get the workbook name from url link.

function getFileName(id) {
var file = SpreadsheetApp.openByUrl(id)
var fileName = file.getName();    
return fileName;  
}

I receive message

"Error You do not have permission to call openByUrl"

I tried

  var file = DriveApp.getFileById(id);

I receive the same sort of message

"No item with the given ID could be found, or you do not have permission to access it. "

Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

0

You cannot use this as a custom function as it requires authorization.

See the Google Documentation

If your custom function throws the error message You do not have permission to call X service., the service requires user authorization and thus cannot be used in a custom function.

To use a service other than those listed above, create a custom menu that runs an Apps Script function instead of writing a custom function. A function that is triggered from a menu will ask the user for authorization if necessary and can consequently use all Apps Script services.

James D
  • 3,102
  • 1
  • 11
  • 21