I have a spreadsheet that is a template. I have a submit button that saves the data in a file (by date and customer name) into a Google Drive Folder.
I want to edit an already submitted template, so I created a dropdown menu that pulls the file name from the folder using this code:
function onOpen() {
list_all_files_inside_one_folder_without_subfolders() }
function list_all_files_inside_one_folder_without_subfolders() {
var sh = SpreadsheetApp.getActiveSheet();
var folder = DriveApp.getFolderById('0B8xnkPYxGFbUMktOWm14TVA3Yjg'); // I change the folder ID here
var list = [];
list.push(['Name']); //,'ID','Size']);
var files = folder.getFiles();
while (files.hasNext()){
file = files.next();
var row = []
row.push(file.getName()) //,file.getId(),file.getSize())
list.push(row);
}
sh.getRange(2,2,list.length,list[0].length).setValues(list);
}
function onEdit(e) {
openFile() }
function openFile(e) {
var sheet = "Sheet1"; // Please set the sheet with the dropdown list.
var range = "A1"; // Please set the range of dropdown list.
if (e.source.getSheetName() == sheet && e.range.getA1Notation() == range) {
var file = DriveApp.getFilesByName(e.value);
if (file.hasNext()) {
var f = file.next();
var url = f.getUrl();
var script = "<script>window.open('" + url + "', '_blank').focus();google.script.host.close()</script>";
var html = HtmlService.createHtmlOutput(script);
SpreadsheetApp.getUi().showModalDialog(html, 'Open ' + f.getName());
}
}
}
I then created a Dropdown of a list of these files by name. I want to create an OnEdit Script that can open a file (by selecting from the Dropdown menu the name of the file).
Any pointers on how to pursue this?