- Trying to copy Comments from one google sheet to a copy of the sheet in another location.
- There doesn't appear to be a copyTo() so I'm trying moveTo()
- Looking for more ideas.
Included this in the code below
It works within the same workbook:
// This works
function copyCellAndComments() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Source_Sheet");
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Destination_Sheet");
sheet.getRange("P21:26").moveTo(targetSheet.getRange("P21:26"));
};
// I run into permissions issues if I try something like
function copyCellAndComments02() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Source_Sheet");
//This didn't work. Told me formatted wrong
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Spreadsheet URL", "Sheetname");
// I tried using SpreadsheetApp.openById() as well as SpreadsheetApp.openByUrl() in the script and it told me I don't have sufficient permissions to run openById or openByUrl.
// (Error
Exception: You do not have permission to call SpreadsheetApp.openByUrl. Required permissions: https://www.googleapis.com/auth/spreadsheets )
// Also tried creating a standalone function and calling the function within the sheet.
function importComments(spreadsheetKey,a1NotationReference) {
return SpreadsheetApp.openByUrl(spreadsheetKey).getRange(a1NotationReference).getComments();
};
Found something online that said it would run if I added a menu and call it from the menu.
// That generates an Error - Exception: Invalid argument: url (line 7, file "MyScripts_RickP")
I tried importrange. Thant copies text in the comment but not as a comment.
Also tried doing it as a query wrapped around the importrange. Same result.
This is the test comment I'm trying to copy
sheet.getRange("P6").moveTo(targetSheet.getRange("P6"));
};
Since I have not found a way to copy the sheet with it's comments intact As Comments (the comment text copies okay but I need to copy it as a comment) to the Archive location.