+ Reply to Thread
Results 1 to 4 of 4

Please help modify a Script by Google

  1. #1
    Forum Contributor
    Join Date
    05-29-2017
    Location
    UK
    MS-Off Ver
    Pro Plus 2016
    Posts
    301

    Please help modify a Script by Google

    Hi, I'm trying to implement the email scheduler script as per:

    https://developers.google.com/apps-s...sending_emails

    can I please ask for help with a few modifications?

    it currently is looking 100 rows down (changed from 2 in the original version)

    the issue is that it returns an error related to MailApp.sendEmail(emailAddress, subject, message);

    emails are being received but this error fires off because there are blank spaces in the Sheet UNDER the initial top 2 emails. Blank spaces below them are unavoidable because the data is always changing so 100 rows changed in a script is taking this into consideration.


    MOD #1: a script is to ignore all blanks so no error message is returned. can it ignore even the spaces in between the contacts and still fire off properly?

    MOD #2: is there a way to add SEND FROM NAME field? currently, it shows the email address


    I'm not a coder, would greatly greatly appreciate the edits in the actual script which I'm pasting below. please?

    a link to the actual files if needed is also below.

    thanking you much in advance.

    https://docs.google.com/spreadsheets...it?usp=sharing


    /**
    * Sends emails with data from the current spreadsheet.
    */
    function sendEmails() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var startRow = 2; // First row of data to process
    var numRows = 100; // Number of rows to process
    // Fetch the range of cells A2:B3
    var dataRange = sheet.getRange(startRow, 1, numRows, 3);
    // Fetch values for each row in the Range.
    var data = dataRange.getValues();
    for (var i in data) {
    var row = data[i];
    var emailAddress = row[0]; // First column
    var message = row[1]; // Second column
    var subject = row[2]; // Third column
    MailApp.sendEmail(emailAddress, subject, message);
    }
    }


    -----

    ERROR IMAGE

    https://www.excelforum.com/attachmen...1&d=1626031113
    Attached Images Attached Images

  2. #2
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Please help modify a Script by Google

    You can check if the e-mail address is empty or not and send the e-mail accordingly as shown in the below modified script;

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-29-2017
    Location
    UK
    MS-Off Ver
    Pro Plus 2016
    Posts
    301

    Re: Please help modify a Script by Google

    thank you, Haluk, greatly appreciated.

    I actually had to hire someone to help with this, here's a script that also includes FROM NAME column:


    /**
    * Sends emails with data from the current spreadsheet.
    */
    function sendEmails() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var startRow = 2; // First row of data to process
    var numRows = 100; // Number of rows to process
    // Fetch the range of cells A2:B3
    var dataRange = sheet.getRange(startRow, 1, numRows, 4);
    // Fetch values for each row in the Range.
    var data = dataRange.getValues();
    for (var i in data) {
    var row = data[i];
    var emailAddress = row[0]; // First column
    var message = row[1]; // Second column
    var subject = row[2]; // Third column
    if (!emailAddress) {continue}
    MailApp.sendEmail(emailAddress, subject, message, {name: row[3]});
    }

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,398

    Re: Please help modify a Script by Google

    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to convert vba to google script
    By Klea in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2021, 10:53 AM
  2. [SOLVED] Google sheets script to download file and save it to google drive folder and use it's data
    By western in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 5
    Last Post: 01-18-2021, 01:31 PM
  3. Help with the Google Sheets script
    By ronin76 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 12-13-2020, 12:28 PM
  4. Needs to add Range (Google App Script)
    By shabby01 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 12-01-2020, 01:51 PM
  5. Google Apps Script for Google Sheets Pulling Formulas from Master to Several Slave Sheets
    By excelroofing in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 08-22-2018, 02:06 AM
  6. Looking for a way to populate cells based off multiple conditions
    By joker5893 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2016, 12:32 PM
  7. [SOLVED] Google excel script help
    By Ditch1983 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 01-21-2015, 10:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1