Introduction

Welcome to the first article in our series on leveraging Google Apps Script (GAS) and Generative AI (Gen AI) to automate and simplify your daily work tasks. If you’re an entrepreneur or professional looking to streamline your workflow and boost productivity, you’ve come to the right place.

In this article, we’ll introduce you to GAS and the incredible potential of using Gen AI tools to enhance your automation capabilities.

What is Google Apps Script?

Google Apps Script is a cloud-based scripting language for light-weight application development in the Google Workspace platform.

Essentially, it allows you to extend and manipulate Google Workspace applications (like Google Sheets, Docs, and Forms) to perform tasks automatically. Think of it as a bridge that connects and enhances the functionality of Google’s suite of tools.

Google Apps Script

Why Use Google Apps Script?

Here are a few reasons why GAS is a game-changer:

  • Automate Repetitive Tasks: Automate daily repetitive tasks such as sending emails, managing data, and creating documents.
  • Enhance Productivity: Free up your time from mundane tasks and focus on more important aspects of your work.
  • Cost-Effective: It’s a free tool available within Google Workspace, making it a cost-effective solution for businesses of all sizes.
  • Integration: Seamlessly integrates with other Google Workspace apps, enhancing their functionality.

The Role of Generative AI in Google Apps Script

Generative AI tools are designed to assist in code creation, making it easier for non-coders to develop scripts. These tools can provide code suggestions, generate scripts based on your requirements, and even debug code.

By leveraging Gen AI, you can create powerful scripts without needing extensive coding knowledge.

Hands-On Demo: Convert Google Sheets to PDF and Email with Custom Menu

This script is designed to simplify the process of converting a Google Sheets document into a PDF and sending it via email. It adds a custom menu item in Google Sheets, allowing users to easily execute the script without needing to open the script editor each time.

This is particularly useful for users who frequently need to share their Google Sheets data as PDF files via email.

Key Features:

  1. Custom Menu: Adds a “PDF Utilities” menu to your Google Sheets for easy access.
  2. Email Prompt: Prompts the user to enter the email address where the PDF should be sent.
  3. Validation: Validates the entered email address to ensure it is correctly formatted.
  4. PDF Conversion: Converts the active Google Sheets document into a PDF file.
  5. Automated Email: Sends the generated PDF as an email attachment to the specified address.
  6. User-Friendly: Provides confirmation messages to guide the user through the process.

How It Works:

  1. onOpen Function: This function runs automatically when the Google Sheets document is opened. It adds a custom menu named “PDF Utilities” to the menu bar, making it easy to access the script.
  2. convertSheetToPDFAndEmail Function: This is the main function that handles the conversion and email process. It:

    • Prompts the user for an email address.
    • Validates the email address format.
    • Converts the active sheet to a PDF file.
    • Sends the PDF file to the provided email address.
    • Displays a confirmation message.
  3. validateEmail Function: A helper function that checks if the provided email address is in a valid format.

Steps to Use the Script:

1. Open Google Sheets:

2. Open Script Editor:

  • In the Google Sheets document, click on Extensions in the menu.
  • Select Apps Script. This will open the Apps Script editor in a new tab.
Open Script Editor

3. Create a New Project:

  • In the Apps Script editor, delete any existing code in the editor.
  • Copy and paste the provided script into the code editor:
Copy Script
Copy Script
Delete & Paste the Provided Script

Next Steps:

4. Rename and Save the Project:

  • Give your project a relevant name, for example, “Convert Sheet to PDF and Email”.
  • Click on the floppy disk icon to save the project.
Rename and Save Project

5. Refresh the Google Sheets Document:

  • Close the Apps Script editor tab.
  • Refresh the Google Sheets document tab. This will trigger the onOpen function to add the custom menu.

6. Run the Script from the Custom Menu:

  • In your Google Sheets document, you will see a new menu item called “PDF Utilities” in the menu bar.
  • Click on PDF Utilities and select Convert to PDF and Email.
  • The first time you run the script, you will be prompted to authorise it to access your Google account.

7. Authorise the Script:

  • An authorization dialog from Google will appear. Click “Continue” and choose your Google account.
  • Click “Allow” to authorise the script to access your Google Sheets and send emails on your behalf.
Authorise the Script

8. Enter Email Address:

  • After authorization, click on “PDF Utilities” and “Convert to PDF and Email” again, a prompt will appear asking you to enter the email address where you want to send the PDF.
  • Enter the email address and click “OK”.
Enter Email Address

9. Confirmation:

  • If the email address is valid, the script will convert the active sheet to a PDF and send it to the provided email address.
  • A confirmation message will be displayed indicating that the PDF has been sent.
  • The recipient should receive the PDF in their email, check inbox for confirmation.

Important Notes:

  • Ensure you have the correct Gmail credentials and are logged in with an account that has permission to access the Google Sheets document.
  • You need to authorise the script to access your Google Sheets and send emails. This is a one-time authorization process.

By following these steps, you can easily set up and run this script to automate the process of converting a Google Sheets document into a PDF and emailing it to a specified address. The custom menu makes it convenient to run the script whenever needed.

In the upcoming articles, we’ll dive deeper into various automation scenarios, providing you with practical examples and step-by-step guides. Stay tuned and get ready to transform your workflow with Google Apps Script and Gen AI!

By Ali Reza Azmi

Founder & Consultant @ Twenty-Four Consulting

By Ali Reza Azmi

Founder & Consultant @ Twenty-Four Consulting

Automation can be Super EASY, and FREE.

With Google Apps Script & Gen AI, you don't need to be a coder to automate anymore!

Watch our demo, download our free cheat sheet, and join the waitlist today.

Google Apps Script Waitlist Image

Related Posts