I try to construct code as follow to make google app script being dynamic to copy image that is stored in cell from on any UserForm sheet which call this function to a log data sheet. The images are located in range D16:D18 in the UserForm. I have more than one identical userForm sheets to allow several user input their data to their UserForm then it will be saved to the same log sheet.
Function MySpecificForm(){
var User1 = "User 1 Form"
addRecord(User1)
//this is one example that calling the add record procedure
}
Function addRecord(WhoIs){
var SourceSheetRange = "'" + "\\" + "'" + WhoIs + "'" + "\\" + "'" + "!D16:D18'"
console.log (SourceSheetRange)
spreadsheet.getRange(SourceSheetRange).copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, true);
spreadsheet.getRange('O7').activate();
}
When I run the code I get error as follow
Though the result already the same as original syntax I get from record macro for CopyTo method. See highlighted in the image below
Hence, it is not working in my code. Is there any lack in my reconstructed string?
This is for google spreadsheet.
With some intriguing events there is no documentation that supports that it supposed to have an error you can raise an Issue with this so you can learn more about this situation, it seems that your issue is with how the range is being called, with multiple tests I figured out that it stops working if you put the code your way. I put up a way that manages to execute the copyTo() by making some changes on the ranges.
Function MySpecificForm()
and Function addRecord(WhoIs)
I corrected the proper casing for this.
Your screenshots show that your Sheet Name is '/'User 1 Form /'
, however there are different variations of this throughout the code. You should really look into that.
Your whole range creation part of your code.
function addRecord(whoIs) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("'"+"/"+"'" +whoIs + "/"+"'");
var range = sheet.getRange("D16:D18");
var dest = ss.getActiveSheet().getRange("O7").activate();
range.copyTo(
ss.getActiveSheet().getActiveCell(),
SpreadsheetApp.CopyPasteType.PASTE_VALUES,
true);
}
function mySpecificForm(){
var user1 = "User 1 Form";
addRecord(user1);
}