How to Send WhatsApp Messages from Excel with Twilio (VBA or No Code)
To send WhatsApp messages from Excel with Twilio, you post each row to Twilio’s Messages API with your Account SID and Auth Token, using whatsapp: in front of both numbers. For tests, Twilio’s WhatsApp sandbox is enough. For real customers you need a registered WhatsApp sender and Meta-approved templates. You can write the VBA yourself, or use a no-code app on top of your Twilio account.
Table of contents
How it works
Twilio connects to the official WhatsApp Business Platform. You send an HTTPS request to Twilio’s Messages API with the recipient, your WhatsApp sender and the text, and Twilio passes it to WhatsApp. Messages come from a business sender registered with Twilio, not from the WhatsApp app on your phone.
That is the key difference from tools that drive WhatsApp Web. The API route is approved by Meta, scales to large volumes and keeps running on Twilio’s servers. In return, WhatsApp’s business rules apply: a registered sender, a 24-hour window for free-form replies, and approved templates for everything else.
Excel’s role is the list: one row per person with the number and the message, and a column for the result. Either VBA reads the rows and calls the API, or an app imports the sheet and does the calling for you. Both options are below.
What you need
You need a Twilio account, its Account SID and Auth Token from the Twilio Console, and a WhatsApp sender. For testing, the sender is Twilio’s shared sandbox number. For real messages, you register your own WhatsApp sender with Twilio, which links it to a Meta business portfolio.
- Twilio account. Usage is billed by Twilio, plus WhatsApp’s own fees for templates. Check Twilio’s WhatsApp pricing page for your countries.
- Account SID and Auth Token. Both are on the Twilio Console home page. Treat the Auth Token like a password.
- A WhatsApp sender. The sandbox for testing, or a sender registered through Twilio’s WhatsApp self sign-up. Its status has to be online before it can send.
- Recipients who opted in. WhatsApp requires that people agreed to get messages from your business.
- Numbers in international format. A plus, the country code and the number, such as +15125550143. My WhatsApp number checker guide has a free formatter that turns local numbers into this format.
Test in the Twilio sandbox
Open the WhatsApp sandbox in the Twilio Console, send the join code it shows from your own WhatsApp to the sandbox number, and you can then send test messages to your phone. The sandbox is for testing only and only reaches phones that joined it.
-
Open the sandbox. In the Twilio Console, go to Messaging, then Try it out, then Send a WhatsApp message. The page shows the sandbox number and a join code made of two words.
-
Join from your phone. In WhatsApp, send join followed by your code to the sandbox number. Twilio replies to confirm. Every phone you want to test with has to join this way.
-
Send a test. Use the sandbox number as the From number in the VBA below, with whatsapp: in front. After you join, you can send free-form text to your phone, because joining opens the 24-hour window.
A sandbox join does not last forever, and the sandbox cannot reach anyone who did not join. Twilio’s WhatsApp sandbox documentation has the current rules. When the tests work, register your own sender and swap the From number. Nothing else in the code changes.
The 24-hour window and templates
You may send any free-form message to a person within 24 hours of their last message to you. Outside that window, WhatsApp only delivers templates that Meta approved in advance. A campaign to people who have not written recently must therefore use an approved template.
Templates are created and submitted in the Twilio Console (Content Template Builder), with placeholders such as {{1}} for a name. Meta reviews each one, and only approved templates can start a conversation. WhatsApp also scores the quality of your messages and applies messaging limits to your business, so check your current limits in Twilio or Meta rather than assuming a fixed number.
For US recipients, Meta paused marketing templates to US phone numbers in April 2025. Utility templates, such as appointment reminders and order updates, were not affected. Check Twilio’s or Meta’s documentation for the current status before you plan a US campaign. I compare the API with the other WhatsApp routes in WhatsApp personal vs Business vs API.
Send from Excel with VBA
Paste a function into a VBA module that posts To, From and Body to Twilio’s Messages endpoint with basic authentication, then loop over your rows. Twilio answers with HTTP status 201 when it accepted a message. The code uses Windows components, so it runs in Excel for Windows only.
Set up a sheet called Messages with the number in column A (international format, such as +15125550143), the message in column B, and empty columns C and D for the result. Then press Alt+F11, insert a module and paste this:
Option Explicit
' From the Twilio Console. Do not share a workbook that contains them.
Private Const ACCOUNT_SID As String = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Private Const AUTH_TOKEN As String = "your_auth_token"
' The sandbox number from the console, or your registered WhatsApp sender
Private Const FROM_NUMBER As String = "whatsapp:+14155238886"
Function SendWhatsApp(ByVal toNumber As String, ByVal body As String) As String
Dim http As Object, url As String, payload As String
url = "https://api.twilio.com/2010-04-01/Accounts/" & ACCOUNT_SID & "/Messages.json"
payload = "From=" & Application.WorksheetFunction.EncodeURL(FROM_NUMBER) & _
"&To=" & Application.WorksheetFunction.EncodeURL("whatsapp:" & toNumber) & _
"&Body=" & Application.WorksheetFunction.EncodeURL(body)
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "POST", url, False
http.setRequestHeader "Authorization", "Basic " & Base64(ACCOUNT_SID & ":" & AUTH_TOKEN)
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send payload
SendWhatsApp = http.Status & " " & http.responseText
End Function
Private Function Base64(ByVal text As String) As String
Dim node As Object
Set node = CreateObject("MSXML2.DOMDocument.6.0").createElement("b64")
node.DataType = "bin.base64"
node.nodeTypedValue = StrConv(text, vbFromUnicode)
Base64 = Replace(node.Text, vbLf, "")
End Function
Sub SendWhatsAppList()
Dim ws As Worksheet, r As Long, result As String
Set ws = ThisWorkbook.Worksheets("Messages")
For r = 2 To ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
If ws.Cells(r, "C").Value = "" Then
result = SendWhatsApp(CStr(ws.Cells(r, "A").Value), CStr(ws.Cells(r, "B").Value))
ws.Cells(r, "C").Value = Left(result, 3) ' 201 = accepted by Twilio
ws.Cells(r, "D").Value = Mid(result, 5) ' Twilio's answer, including the message SID
Application.Wait Now + TimeSerial(0, 0, 1)
End If
Next r
End Sub
Run SendWhatsAppList with Alt+F8. Rows that already have a status are skipped, so you can run it again after fixing a failed row. Format column A as Text before typing numbers, or Excel drops the plus sign. EncodeURL exists in Excel 2013 and later on Windows.
A 201 means Twilio accepted the message, not that it was delivered. Delivery happens a moment later. You can look up each message in the Twilio Console’s message logs, or add a status callback URL if you have a server to receive it.
Watch out: the Auth Token sits in plain text in the workbook. Keep the file on your own PC, never email it, and rotate the token in the Twilio Console if the file ever leaves your hands.
Send an approved template from VBA
Replace the Body parameter with ContentSid, the ID of your approved template (it starts with HX), and ContentVariables, a small JSON text that fills the placeholders. Everything else in the request stays the same.
payload = "From=" & Application.WorksheetFunction.EncodeURL(FROM_NUMBER) & _
"&To=" & Application.WorksheetFunction.EncodeURL("whatsapp:" & toNumber) & _
"&ContentSid=HXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & _
"&ContentVariables=" & Application.WorksheetFunction.EncodeURL( _
"{""1"":""" & firstName & """,""2"":""" & appointmentTime & """}")
Here {{1}} in the template becomes the first name and {{2}} the appointment time, taken from two more columns. A double quote inside a name would break the JSON, so keep the source columns clean. Free-form Body text still works inside the 24-hour window, for example when you answer a customer who just wrote to you.
The no-code route
TextBay, a Windows app I built, connects to your own Twilio account with your Account SID and Auth Token and sends SMS, MMS and WhatsApp messages from a contact list you import from Excel or CSV. It replaced my older Excel-based Twilio Blaster, which is no longer sold.
For WhatsApp, TextBay sends through Twilio’s official WhatsApp channel, so you still register a sender once. The app then handles the parts the VBA above leaves to you: its Templates page lists your WhatsApp templates with their approval state (approved, pending, or rejected with Meta’s reason), ready to fill and send, and the inbox shows for each WhatsApp conversation whether the 24-hour window is open. Replies appear like a chat, SMS and WhatsApp side by side, and opt-out keywords are detected on WhatsApp too.
The free trial sends 20 messages, one time, with every feature. Twilio’s own usage charges apply either way. The TextBay WhatsApp rules page sums up what Meta requires, and my guide to bulk SMS through Twilio without code covers the SMS side, including US 10DLC registration.
Common errors
Most rejections come from a wrong From or To format, a sender that is not set up for WhatsApp, or a free-form message outside the 24-hour window. Twilio’s answer text in column D names the error code, which you can look up in Twilio’s error dictionary.
| What you see | Usual cause | Fix |
|---|---|---|
| Status 401, error 20003 | Wrong Account SID or Auth Token | Copy both again from the Twilio Console |
| Error 21211 | The To number is not a valid phone number | Use +, country code and number, no spaces |
| Error 63007 | Twilio found no WhatsApp channel for the From number | Keep whatsapp: in front of the sender, and use the sandbox or a registered sender |
| Error 63016 | Free-form message outside the 24-hour window | Send an approved template instead |
| Status 201, but nothing arrives | The recipient did not join the sandbox, or WhatsApp could not deliver | Check the message log in the Twilio Console |
| Run-time error on EncodeURL | Excel for Mac or an Excel version before 2013 | Use Excel 2013 or later on Windows |
Twilio or your own WhatsApp account
Use Twilio when you send business messages at volume, need official delivery reports, or want messages to keep running without a PC. Use your own WhatsApp account when you message people who know your number, want replies in your normal WhatsApp and do not want templates or approvals.
Sending from your own account works through WhatsApp Web, and that is what my SendCommander app does: no API, no templates, no per-message fees, but slow, careful sending and a real risk of restrictions if people report you. The full walkthrough is in how to send WhatsApp messages from an Excel list. The older video for this post also mentioned a VBA and Selenium approach to WhatsApp Web. That Excel tool was WhatsApp Blaster, and SendCommander has replaced it.
Send WhatsApp, SMS and MMS messages through your own Twilio account from a Windows app. Import your Excel list, fill approved WhatsApp templates, and answer replies in one inbox. No code required.
