How to copy my google doc

200 views
Skip to first unread message

Ellen Liu

unread,
Aug 14, 2021, 10:17:04 PM8/14/21
to Google Apps Script Community

This my scripts,  I donot know why it doesn't work.

function makeCopy() {

// gets the name of the original file and appends the word "copy" followed by the timestamp stored in formattedDate
var name = DocumentApp.getActiveDocument().getName() + " Copy  of  ";

var destination = DriveApp.getFolderById("1D-665l1dxAvCTZ7lLeLEDtCLdtwy9VH-");

// gets the current Google Sheet file
var file = DriveApp.getFileById(DocumentApp.getActiveDocument().getId())

// makes copy of "file" with "name" at the "destination"
file.makeCopy(name, destination);
}

Bennett, Scott

unread,
Aug 14, 2021, 10:20:07 PM8/14/21
to google-apps-sc...@googlegroups.com
Did you mean Google Doc file in your comment?  

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/af97bbfa-52b0-4acc-a08d-acefaf3fd6b1n%40googlegroups.com.


--


Martin Molloy

unread,
Aug 15, 2021, 2:49:35 AM8/15/21
to google-apps-sc...@googlegroups.com
The line " var file = DriveApp.getFileById(DocumentApp.getActiveDocument().getId())"

gets the ID number of the file not the file it should be

var file = DriveApp.getFileById(DocumentApp.getActiveDocument()

Hope that helps



--

ธีระศักดิ์ คนตรง

unread,
Aug 16, 2021, 11:02:37 AM8/16/21
to Google Apps Script Community
Solve by change code to this:

file.makeCopy(destination).setName(name);

ในวันที่ วันอาทิตย์ที่ 15 สิงหาคม ค.ศ. 2021 เวลา 13 นาฬิกา 49 นาที 35 วินาที UTC+7 Martin Molloy เขียนว่า:
Reply all
Reply to author
Forward
0 new messages