Cliff
Cliff

Reputation: 1

create a button that emails the google sheet

In a google sheet that I've created, I have a place where I can put in an email address (in my sheet, it is actually located at cell I6. What I'm needing to do is create a script that will pull this email address out of I6 and then email the sheet to that email. I don't want to email every sheet, just that page that has the button I've created.

The main script I have thus far is:

function sendemail() {
    MailApp.sendEmail("email address", "subject", "body");
}

Where it says "email address", I want it to pull the contents of cell I6. What is the coding to do this?

Any help is greatly appreciated.

Thanks, Cliff

Upvotes: 0

Views: 1666

Answers (1)

Mr.Rebot
Mr.Rebot

Reputation: 6791

Since UI Service is deprecated, the only option is to assign a script to an image or drawing.

I've followed this tutorial - Google Spreadsheet Button to Run Scripts

Here is the code snippet:

function highFive(){
  Browser.msgBox("High Five!");
}

enter image description here

Once I click the image this will happen:enter image description here

Also in the tutorial, there is a snippet regarding sending an email with the button:

function email(){
  var rng = SpreadsheetApp.getActiveSheet().getActiveRange()
  var email = rng.getValues()[0];
  GmailApp.sendEmail(email[0], email[1], email[2]);
}

enter image description here

Hope this helps.

Upvotes: 1

Related Questions