การเริ่มต้นใช้งานการทำงานอัตโนมัติอย่างรวดเร็ว
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สร้างและเรียกใช้การทำงานอัตโนมัติแบบง่ายที่สร้างเอกสาร Google เอกสารและ
ส่งลิงก์ไปยังเอกสารให้คุณทางอีเมล
วัตถุประสงค์
- ตั้งค่าสคริปต์
- เรียกใช้สคริปต์
ข้อกำหนดเบื้องต้น
หากต้องการใช้ตัวอย่างนี้ คุณต้องมีข้อกำหนดเบื้องต้นต่อไปนี้
- บัญชี Google (บัญชี Google Workspace อาจต้อง
ได้รับการอนุมัติจากผู้ดูแลระบบ)
- เว็บเบราว์เซอร์ที่มีสิทธิ์เข้าถึงอินเทอร์เน็ต
ตั้งค่าสคริปต์
หากต้องการสร้างการทำงานอัตโนมัติ ให้ทำตามขั้นตอนต่อไปนี้
- หากต้องการเปิดเครื่องมือแก้ไข Apps Script ให้ไปที่
script.google.com
หากนี่เป็นครั้งแรกที่คุณเข้าชม
script.google.com
ให้คลิกดูแดชบอร์ด
- คลิกโครงการใหม่
ลบโค้ดในตัวแก้ไขสคริปต์ แล้ววางโค้ดด้านล่าง
คลิกบันทึก 
คลิกโปรเจ็กต์ที่ไม่มีชื่อ
ป้อนชื่อสคริปต์ แล้วคลิกเปลี่ยนชื่อ
เรียกใช้สคริปต์
หากต้องการเรียกใช้สคริปต์ ให้ทำตามขั้นตอนต่อไปนี้
- คลิกเรียกใช้
ให้สิทธิ์สคริปต์เมื่อได้รับข้อความแจ้ง
หากหน้าจอคำยินยอมของ OAuth แสดงคำเตือนว่า แอปนี้ยังไม่ได้รับการยืนยัน
ให้ดำเนินการต่อโดยเลือกขั้นสูง >
ไปที่ {ชื่อโปรเจ็กต์} (ไม่ปลอดภัย)
เมื่อสคริปต์ทำงานเสร็จแล้ว ให้ตรวจสอบอีเมลในกล่องจดหมาย Gmail
เปิดอีเมลแล้วคลิกลิงก์เพื่อเปิดเอกสารที่คุณสร้าง
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eThis script automates the creation of a Google Doc and emails you a link for access.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need a Google Account and web browser to use this automation script.\u003c/p\u003e\n"],["\u003cp\u003eThe script involves pasting provided code into the Apps Script editor and running it after authorization.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful execution, you'll receive an email containing the link to your newly created Google Doc.\u003c/p\u003e\n"],["\u003cp\u003eExplore further options to extend functionalities with Google Docs, Sheets, and Slides or learn basic JavaScript.\u003c/p\u003e\n"]]],[],null,["# Automation quickstart\n\nBuild and run a simple automation that creates a Google Docs document and\nemails you a link to the document.\n\nObjectives\n----------\n\n- Set up the script.\n- Run the script.\n\nPrerequisites\n-------------\n\nTo use this sample, you need the following prerequisites:\n\n- A Google Account (Google Workspace accounts might require administrator approval).\n- A web browser with access to the internet.\n\nSet up the script\n-----------------\n\nTo build the automation, take the following steps:\n\n1. To open the Apps Script editor, go to [`script.google.com`](https://script.google.com). If this is the first time you've been to `script.google.com`, click **View Dashboard**.\n2. Click **New project**.\n3. Delete any code in the script editor and paste in the code below.\n\n templates/standalone/helloWorld.gs \n [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/templates/standalone/helloWorld.gs) \n\n ```javascript\n /**\n * Creates a Google Doc and sends an email to the current user with a link to the doc.\n */\n function createAndSendDocument() {\n try {\n // Create a new Google Doc named 'Hello, world!'\n const doc = DocumentApp.create('Hello, world!');\n\n // Access the body of the document, then add a paragraph.\n doc.getBody().appendParagraph('This document was created by Google Apps Script.');\n\n // Get the URL of the document.\n const url = doc.getUrl();\n\n // Get the email address of the active user - that's you.\n const email = Session.getActiveUser().getEmail();\n\n // Get the name of the document to use as an email subject line.\n const subject = doc.getName();\n\n // Append a new string to the \"url\" variable to use as an email body.\n const body = 'Link to your doc: ' + url;\n\n // Send yourself an email with a link to the document.\n GmailApp.sendEmail(email, subject, body);\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n }\n }\n ```\n4. Click Save .\n\n5. Click **Untitled project**.\n\n6. Enter a name for your script and click **Rename**.\n\nRun the script\n--------------\n\nTo run the script, take the following steps:\n\n1. Click **Run**.\n2. When prompted, authorize the script.\n If the OAuth consent screen displays the warning, **This app isn't verified** ,\n continue by selecting **Advanced** \\\u003e\n **Go to {Project Name} (unsafe)**.\n\n3. When the script execution completes, check your [Gmail inbox](https://mail.google.com)\n for the email.\n\n4. Open the email and click the link to open the document that you created.\n\nNext steps\n----------\n\n- [Extend Google Docs](/apps-script/guides/docs)\n- [Extend Google Sheets](/apps-script/guides/sheets)\n- [Extend Google Slides](/apps-script/guides/slides)\n- [Basic JavaScript features](/apps-script/guides/services#basic_javascript_features)"]]