I have several different Google Sheets workbooks with multiple pages that I'm trying to have sync into a master file whenever they are edited. I cannot have all of the people on the separate documents editing the primary document. In using the Script Editor, I have this:
function onEdit() {
SpreadsheetApp.getUi().createMenu("Admin Settings")
.addItem("Import Data", "importData")
}
var sourceSpreadsheetID = "TO UPDATE";
var sourceWorksheetName = "TO UPDATE";
var targetSpreadsheetID = "TO UPDATE";
var targetWorksheetName = "TO UPDATE";
function importData() {
var thisSpreadsheet = SpreadsheetApp.openById('1yoF-IQo_XKD1X6N_z_54X8N4Akm4dgyUTJ9Av6wQ0Ps');
var thisWorksheet = thisSpreadsheet.getSheetByName("Barnhardt");
var thisData = thisWorksheet.getDataRange();
var toSpreadsheet = SpreadsheetApp.openById('1ktwfwRN3cRCvpwkiFbZMEud-9ez8ZVGciu5ejrNiGAU');
var toWorksheet = toSpreadsheet.getSheetByName("Barnhardt");
var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(), thisData.getNumColumns()) toRange.setValues(thisData.getValues());
}
but I can't figure out why it won't work. The script editor says that it was successful. I also tried to add a trigger so that every time the document is edited, it will update the master document, but I'm not sure how to add that to the script. Help?
onEdit()
to `onOpen()": assuming that you want the menu at all, you'll want to create it when you open the spreadsheet not when you edit a field.