"It seems that you can automate spreadsheets and Gmail using Google Apps Script (GAS). But I've never done programming before..." What I would like such people to try is Having Gemini write the GAS code.
As of February 2026, Google's AI "Gemini" has become quite good at generating GAS code. All you have to do is tell them in Japanese, ``I want to do something like this,'' and they'll give you the code to copy and paste.
This article provides step-by-step instructions for someone with no programming experience to use Gemini to generate GAS code and automate Google Spreadsheet work. We'll also show you a trick to use the "Gem" feature to turn frequently used prompts into templates.
What is GAS (Google Apps Script)?
GAS is a free programming environment provided by Google. A JavaScript-based scripting language that allows you to automatically operate Google Workspace services such as Google Spreadsheets, Gmail, Google Drive, and Google Calendar.
Roughly speaking, it's something like "Google's version of Excel macros". For example, you can do something like this.
- Automatically aggregate spreadsheet data every day
- Automatically transfer emails with a specific Gmail subject to a spreadsheet
- Send notifications to Slack when Google form responses are received
- Send a list of calendar events by email
However, there is one problem. You have to write code. Memorizing JavaScript syntax and researching how to use Google's unique APIs...the reality was that it was a difficult hurdle for people with no programming experience.
This is where the approach of having AI write the code comes into play.
Basic flow of having Gemini write GAS code
The basic steps to generate GAS code with Gemini are very simple.
Step 1: Open Gemini
Go to Gemini (gemini.google.com) and log in. Code generation is available on the free plan, but Gemini Advanced (2,900 yen per month) is more accurate and can handle long codes (as of February 2026).
Step 2: Tell us what you want to do in Japanese
Prompts (instructions) can be in Japanese. The key is to be specific about what you do, where you go from, where you go, and when.
For example, it looks like this.
Use Google Apps Script to create a code that automatically aggregates the data in columns A to D in the sheet "February" of the spreadsheet "Sales Management" every morning at 9 a.m., and writes the total to the last row of column E.
With just this, Gemini will generate the code for you. The AI will also have trouble if the instructions are vague (such as ``total the numbers appropriately''), so the trick is to be specific.
Step 3: Paste the code into GAS editor
After copying the generated code, paste it into the GAS editor.
- Open Google Sheets
- Click "Extensions" → "Apps Script" in the menu
- When the editor opens, delete all
function myFunction() { }written from the beginning and paste the code generated by Gemini - Click on the “Save” button (💾 icon)
- Click the “Run” button (▶ icon)
The first time you run it, a dialog box saying "Authorization required" will appear. This is simply because GAS is asking for permission to access the spreadsheet, so you can proceed by "Check permission" → select your Google account → "Allow".
Step 4: Ask Gemini if there is an error
It is not uncommon to run your code and get an error. In fact, it's only natural that it should come out at first.
If an error occurs, copy the error message displayed in red and paste it into Gemini. Just say, "This error occurred. Please fix it," and the AI will identify the cause and provide a fix code.
Google's official troubleshooting guide is also helpful, but in most cases it's faster to ask Gemini.
Create a template for the GAS generation prompt using the "Gem" function
Writing the same instructions every time is tedious. This is where Gemini's Gem function comes in handy.
Gem is a function that allows you to save preset instructions (custom instructions) as a template. In other words, you don't have to write the prerequisite "act as a GAS expert" every time, and the gem will generate optimal code just by starting it.
How to make a GAS exclusive gem
- Open Gem Manager from the sidebar of Gemini
- Click New Gem
- Enter the name (e.g. "GAS Code Craftsman")
- Write the following in the custom instructions field:
You are an expert in Google Apps Script (GAS). Please follow the rules below to generate code:
・Insert comments in Japanese in the code
・Follow the user's instructions for the spreadsheet sheet name and cell range
・Be sure to include error handling (try-catch)
・Optimize so that the execution time does not exceed 6 minutes
・Explain "how to use" within 3 lines after the code
- Click Save
Now, next time you just select the "GAS Code Craftsman" gem, you will receive the same quality code every time. How to use Gem is explained in detail in Google official help.
As of February 2026, Gem functionality is available in Gemini Advanced, Business, Enterprise, and Education plans. Please note that this cannot be used with the free plan.
5 points to note about AI-generated GAS code
The code written by Gemini is useful, but it is dangerous to rely on it too much. As pointed out in Yoshidumi's explanatory article, be careful of the following points.
1. You may be using an old API
AI learning data is not necessarily the latest. It may generate obsolete functions or code that is written in an outdated manner. If an error occurs, add an additional instruction such as ``Rewrite with the latest API.''
2. Wrong sheet name/cell range
Since AI does not see the actual contents of the spreadsheet, it may specify a sheet name or cell range that does not exist. The golden rule is to tell the sheet name accurately.
3. Execution time limit (6 minute rule)
GAS has a limit of up to 6 minutes per run (30 minutes for Google Workspace accounts). Code that processes large amounts of data may run into this limit, so tell them to "optimize with execution time in mind."
4. Permission issues
GAS can access not only spreadsheets but also Gmail, Drive, Calendar, etc. Check whether the code generated by the AI contains access to unintended services on the permission confirmation screen when you run it for the first time.
5. Handling of personal information
When sending prompts to Gemini, avoid pasting the contents of the spreadsheet (customer names, email addresses, etc.) verbatim. It is enough to just convey the structure, such as "Customer name in column A, email address in column B."
Practical example: Automatically send daily spreadsheet reports
Here, as a specific example, we will introduce the steps to have Gemini create a GAS that "automatically sends spreadsheet sales data by email every morning."
Instructions (prompts) to Gemini
Create code to perform the following processing using Google Apps Script:
・Refer to the sheet “February” in the spreadsheet “Monthly Sales”
・Column A contains the date and column B contains the sales amount
・Get the sales amount in the last row and the total of the entire B column
・Send the acquired information by email in the format of "Today's sales: ◯◯ yen / Monthly cumulative total: ◯◯ yen"
・Send to: xxx@example.com
・The subject is "[Daily report] Sales report"
Setting automatic execution (trigger)
Once the code is created, set the trigger to run automatically every morning.
- Click “⏰ Trigger” from the left menu of the GAS editor
- Click “Add Trigger”
- Select the function to execute (Function name generated by Gemini)
- Set event source to "Time-driven"
- Select "Date-based timer" → "8 AM - 9 AM"
- Click “Save”
You will now receive the spreadsheet sales data automatically by email every morning. You can do this even with zero programming knowledge.
FAQ
Can I generate GAS code with Gemini for free?
Yes, it is possible to generate GAS codes even with Gemini's free plan. However, Gemini Advanced (2,900 yen per month) is better in terms of accuracy and compatible cord length. To use Gem features, you need an Advanced plan or higher (as of February 2026).
Can I create a GAS code with ChatGPT? What is the difference with Gemini?
It is also possible to generate GAS code with ChatGPT. However, since Gemini is developed by Google, its API knowledge related to Google Workspace tends to be more accurate. No matter which method you use, errors may occur, so it is important to run and check.
Are there any concerns that company data will be leaked due to the GAS code generated by AI?
Since the GAS code itself is executed on Google's servers, there is basically no data leakage when the code is executed. However, if you include actual data (customer name, sales amount, etc.) when sending prompts to Gemini, it may be used as training data for AI. Just tell us the structure and don't include the actual data.
When GAS doesn't work due to an error, is there anywhere else I can turn to other than Gemini?
Google Apps Script official documentation and Stack Overflow (English) are standard. If you search for "GAS 〇〇 error" in Japanese, you can often find solutions to the same symptoms.
References
- Google Apps Script overview — Google for Developers
- How to use Gems — Gemini App Help, Google
- Is the Google Apps Script code written by AI okay? Precautions when automatically generating with generation AI — Yoshizumi Co., Ltd.
- Troubleshooting | Apps Script — Google for Developers
- A must-see for those who are frustrated with programming! How to streamline back office operations with GAS automation using Gemini — Hinata Consulting






