Scroll to Top
💻
Free Code
Users get ready-to-use code at no cost.
📋
Easy Copy
Copy and use the code instantly.
Quick Learning
Understand concepts fast and clearly.
📝
Step-by-Step
Follow simple instructions to implement.
📅 August 16, 2024 💻 Tutorial ⭐ Beginner Friendly

Send WhatsApp Message from Google Sheet in One-Click

Author Avatar

Ashish Dwivedi

Editorial Team • Tech Writer

About This Tutorial

With Google Sheets and Google Apps Script, you can send WhatsApp messages in one click using a pre-filled WhatsApp API link. Add the message and phone number in the sheet, create a custom button, and trigger a script that opens the WhatsApp chat automatically in a new browser tab.
  1. Step 1: Click on the Copy button to copy the code snippet.
  2. Step 2: Paste the copied code into your project’s script editor.

Apps Scripts Blog

Read Blog

 

📂 javascript
⚡ script1.js
⚡ script1.js
function createWhatsAppHyperlink() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var lastRow = sheet.getLastRow();

  // ✅ Assuming data starts from row 2 and you have 4 columns (A, B, C, D)
  var dataRange = sheet.getRange(2, 1, lastRow - 1, 4);
  var data = dataRange.getValues();

  var whatsappLinks = [];

  for (var i = 0; i < data.length; i++) {
    var phoneNumber = data[i][1]; // Assuming phone numbers are in column B (index 1)

    // Merge data from columns A, C, and D
    var message = data[i][0] + " - " + data[i][2] + " - " + data[i][3];

    // Create WhatsApp API URL with encoded message
    var whatsappLink = "https://api.whatsapp.com/send?phone=" + phoneNumber + "&text=" + encodeURIComponent(message);

    var displayText = "click to send"; // Text to display as hyperlink

    // Create Google Sheets HYPERLINK formula
    var hyperLinkFormula = '=HYPERLINK("' + whatsappLink + '", "' + displayText + '")';

    whatsappLinks.push([hyperLinkFormula]);
  }

  // Write the formulas into column E starting from row 2
  var columnE = sheet.getRange(2, 5, whatsappLinks.length, 1);
  columnE.setFormulas(whatsappLinks);

  Logger.log("✅ WhatsApp hyperlinks with display text have been created successfully!");
}