How to automatically close Google Forms at a specified time

Google Forms are very versatile and useful, but the standard features alone do not allow forms to close automatically (close acceptance).

So, in this article, I will explain how to automatically close a form.
The procedure uses Google Apps Script, but it is very simple, so please don’t get defensive.

As a supplement, I have also included a method to automatically “open” forms.

Create Scripts

Create a script to close the form automatically.

Open the menu and press Script Editor.

Script Editor is selected from the menu in the upper right corner of the Google Forms editing screen.

When the script editor starts up, delete all the pre-input scripts “myFunction” as they are unnecessary.

Then paste the code below.

Delete the pre-populated functions in the script editor and paste the scripts in this article.
function closeForm() {
  const form = FormApp.getActiveForm();

When this is done, save the script. (You can save it by pressing the floppy disk icon button.)

Script testing and authorization

Now that we have created the script, let’s give it a try and press the > Run button to execute it.

The first time you run this script, you must authorize it.
A dialog box will appear asking for authorization, press Review Permissions.

A dialog box titled "Authorization Required" will appear, press the Review Permissions link.

Select your account.

When the "Choose an account" dialog box appears, select an account.

Displayed under certain circumstances:
If you see the alert in the image below, Press “Advanced” and then “Go to Unlimited project (unsafe)”.

Press "Advanced" when the "Google hasn't verified this app" dialog box appears.
Then press "Go to <project name> (unsafe)"

press Allow.

The permissions required by the project (script) are displayed. Press Allow at the bottom of the screen.

When the authorization is complete, the script is executed.
If the execution log shows “Execution Completed”, the script has been executed correctly.

The script execution log is shown and the completion time of the script is also displayed.

Go back to the Google forms screen and open the “Responses” tab. You will see that the form is now closed.

The "Responses" tab of the Google Forms edit screen shows that the form is closed.

The test is now complete.
If necessary, you may return the form to the open state on this screen.

Set a time-specified trigger

Now that we have a script that closes the form, you can set it to run automatically at a specified time.

To do so, choose TriggersAdd Trigger.

Press the Add Trigger button from the Trigger menu in the Script Editor

Select Time-driven trigger as the event source and Specific date and time as the type of time based trigger.

Then, in the “Enter date/time” field, enter the date/time you want the form to close automatically and save.

In the dialog for setting up triggers, the event source, time base trigger type, and specified time are set.

On the “Triggers” screen, you can see the triggers you have saved.

The Triggers screen in the Script Editor showing the triggers that have been set.

This completes the trigger setup. The form should close automatically at the specified time.

See execution history

On the “Executions” screen, you can see the execution history.

Script Editor's Executions screen showing script execution history.

I found that the trigger I set up started at 12:00:36 AM, ran for 0.713 seconds.

Unfortunately, there seems to be a delay of a few seconds to a few dozen seconds….

Extra 1: Automatically open forms

If you want the form to open automatically, add the following script.

function openForm() {
  const form = FormApp.getActiveForm();

The difference from the previous function is the name of the function and the arguments of the “setAcceptingResponses” method.
The argument is set to true instead of false.

When creating a trigger, specify openForm in the “Choose which function to run” field.

Extra 2: Notify by e-mail when the process is completed

If you would like to receive an email notification when the process is complete, modify the script as follows.

function closeForm() {
  const form = FormApp.getActiveForm();
  const recipient = "";         // Recipient's email address
  const subject = "Form closed.";               // Subject of the email
  const body = "Application form closed.";      // Body of the email
  GmailApp.sendEmail(recipient, subject, body) 

Please change the recipient, subject, and body to match your needs.

If you are creative, you can include the title of the form and the URL to view the responses in the email.

function closeForm() {
  const form = FormApp.getActiveForm();
  const formName = form.getTitle();
  const url = form.getEditUrl() + "#responses";
  const recipient = "";
  const subject = formName + " is now closed.";
  const body = formName + " is now closed.\nPlease check the following URL.\n" + url;
  GmailApp.sendEmail(recipient, subject, body) 

Since added the Mail Sending Function, you need to authorize it again.

It seems that the getTitle method sometimes does not get the title of the form properly. If this is the case, try changing the title and saving it from the Google Forms edit screen.

Then run the script again and you should be able to retrieve the form title.

If you run this script, you will receive the email in the image below.

The title of the form and the URL to view the form Responses are included in the email.

Extra 3: Close the form according to the number of responses

It is also possible to automatically close the form when the number of responses reaches a limit you set.

For reference, the code and trigger settings are shown below.

function closeForm() {
  const form = FormApp.getActiveForm();
  const limit = 10;
  const responses = form.getResponses();
  if (responses.length >= limit){

The limit = 10 in the third line of the code means that the form will be closed when 10 responses are received. Change this value to match your requirements.

This process must be performed each time a form response is received.

This process should be executed each time a form response is received. Therefore, when setting up the trigger, select From form as the event source and On form submit as the event type.

The event source and event type are set on the trigger setup screen.


Copied title and URL