Call Your Spreadsheet, Text Your Database – Using Twilio From Excel and Access

Devin Rader

If you’ve used Windows like I have for the last 20 years, likely some of the most familiar pieces of software for you are Excel and Access. And even though these two pieces of software have thousands of features, to date apparently no one at Microsoft has ever thought to put a phone in them. Well today that changes.

For better or worse, Microsoft Excel and Access are the backbone that power many organizational processes in companies big and small. Excel alone has been know to power the financial models of many businesses, and even entire countries. The applications have won this honored place in the hearts and minds of business workers in part because both applications are highly customizable through multiple means, one of which is by creating custom logic using Visual Basic for Applications (VBA), an implementation of the venerable Visual Basic language. Extending Office using VBA is popular because it is approachable by non-developers, easy to learn, and offers a way to quickly to add custom logic to Office applications.

In this post I’ll show you how you can use VBA to extend both Excel and Access, letting you send SMS messages and make phone calls using the Twilio API right from inside those apps.

Send SMS Messages from Excel

One of the most common uses for Excel as a simple flat database. Its trivial to create a new spreadsheet, type in your column headers and start making lists of stuff, so let’s use that scenario to demonstrate how easy it is to use VBA to interact with the Twilio API.

Let’s pretend for a moment that I am the coach for a youth soccer team. To keep track of the kids on the team, their parents and their contact information, I’ve created a new spreadsheet in Excel.


Since the spreadsheet already contains all of the contact info for the players’ parents, it would be great if I could just send SMS messages to the parents for things like canceled practices and game reminders right from within Excel. To do that I need to extend the spreadsheet.

I’ll start by creating some UI that lets me initiate the process of sending a text message. Excel 2007 and later let me add new elements to the ribbon like tabs, groups and buttons, and then listen for events from those elements in my VBA code.  So I’ll add a new button that lets me send text messages.

The easiest way to add elements to the ribbon is by using the Office Custom UI Editor, which I downloaded here. 

This application lets me define new elements using the ribbons UI XML schema.  Below is the XML I created to add a new tab, group and button to the ribbon:

The most important attribute to point out in the XML is the onAction attribute located on the button element. This attribute is how you tell Excel which VBA subroutine to call when the button is clicked. In my case I’ve told Excel that when the button is clicked I want to execute a subroutine named conSendSms, which I’ll write in just a bit.

When I save the spreadsheet in the custom UI editor it saves the XML directly in the file, so when I reopen the spreadsheet in Excel I now see that there is a new tab named TWILIOSO that contains a single group, which itself contains a single button.


Now I need write the code to that will actually send my SMS messages.

To open the VBA editor in Excel, press Alt+F11, or open the DEVELOPER tab and click the Visual Basic button, which you can do by customizing the ribbon you can make the tab visible:


I’ll start coding in the editor by adding a new module to the project and then adding the subroutine that will handle my new ribbon button being clicked:

To test this I can go back to Excel and click my Send SMS button. The message box will appear. Pretty simple, huh?

Next, I want to create a custom dialog that will let me specify the message I want to send. To do this I’ll create a new User Form in my project and then added a textbox and two buttons: Send and Cancel.

When I click the Cancel button I want to close the dialog (obviously) and when I click the Send button I want to send SMS messages.

In order to tell my VBA code who to send messages to, I’ll create a Selection by selecting a set of cells in my spreadsheet. Now in the Send buttons click event, I can loop over each of the selected rows in the Selection:

Finally, I need to have my VBA code talk to the Twilio REST API to tell it to send the SMS messages. Using the Twilio API means making an HTTP request to the proper Twilio URL and providing the required parameters: a from phone number, a to phone number and a message.

To make the HTTP request, I’m going to use the MSXML2.XMLHTTP60 object which is included in the Microsoft XML 6.0 library, so I need to reference it in the project:

Once the XML library referenced, I’ll use the libraries APIs to create and send an HTTP request to Twilio inside of a function named SendSms. When I send the request I need to make sure I configuring it to authenticate with my Twilio credentials (which I can get from my Twilio account dashboard) and to send the require parameters in the request body:

Once the request is sent I can check the response sent from Twilio and provide the appropriate user feedback in case an error occurred.

Now all I need to do is update my loop to call the SendSms function, passing in the from, to and message parameters:

That’s all there is to it. A few lines of VBA code and I’m sending text messages right from Excel. Of course you could certainly take the time to make this more robust and generic, extending the dialog to allow you to specify the column containing the phone number (I simply hard coded it in my sample), or adding code that allows you to merge other cells from the spreadsheet dynamically into your message.

Feel free to download the spreadsheet I created for this post and play with the code yourself.

Sending SMS Messages Using Access

Sending text messages from Access is a bit different, mostly because Access has, for many versions, had the concept of Forms built right into it. Access Forms allow you to develop fairly complex applications right within Access and and make it trivial to access the data in the underlying database. I’ll show you how you can send SMS messages right from Access by using the same soccer coach scenario described in the previous section.

To start I’ve created a simple database containing two tables: Teams and Players and then dropped in the same data I had in my Excel spreadsheet. I created a relationship between Teams and Players that will allow me to associate a set of players with a specific team:
Next, I created a new query named Roster that returns an INNER JOIN between the Teams and Players tables, providing me with a single list which I will use as the data for my form.

Now that I’ve got the basic database setup, I can create the form that I will use to send the messages. Unlike Excel where I had to add a button to the Ribbon in order to show my dialog, Access already had Forms built into it so I can add a new Dialog form and add some controls to it.
Screen Shot 2013-08-14 at 10.43.20 AM

Like in my Excel dialog, I added a text area where I can type my message and two buttons to close the dialog, or send the messages. And also similar to my form in Excel, when I click the OK button on my Access form, it loops over a set of records and sends an SMS for each.

In Access however, since the underlying data is a traditional SQL database, instead of needing to select a set of cells to loop over, I can simply run the Roster query I created earlier and loop over the records returned from the query.

I can access the fields in each record by specifying the query name and then the field name:

Finally, I’ll add the reference to the Microsoft XML 6.0 library and then drop into my form the same SendSms subroutine that I created for the Excel sample, and now I’m sending SMS messages from Access.

And like with the previous example, I highly encourage you to download and check out the sample Access database I created for this post.

Making Phone Calls From Access

So now that I’ve shown you how easy it is to send text messages from Excel and Access, lets take a look at how I can change the code to have Twilio initiate an outbound phone call to each of my players and let them know that practice will be canceled because of bad weather.

To do this I have to make two changes to my code. First, I need to change the Twilio URL that I’m making my HTTP request to. The URL I use to tell Twilio initiate phone calls is different than the URL I have been using to tell Twilio to send SMS messages.

This new URL also requires a different set of parameters be sent with it. Where sending an SMS requires the from, to, and message parameters, initiating an outbound call requires the from, to and url parameters.

This takes me to the second change I need to make. I need to create a URL that Twilio can request to get instructions on how to proceed when the call is answered. We call those instructions TwiML. To make it super simple to give the those instructions to Twilio, I’m going to use the Simple Message Twimlet service to generate the TwiML for me.

The Simple Message Twimlet knows how to accept a string of text as a URL parameter and convert that string into TwiML that uses the verb. When the generated TwiML is returned to Twilio, Twilio will convert the text inside of the verb into a voice, which the person who answers the call can hear.

The URL below shows how to send the message I want the caller to hear to the Twimlet. You can see the TwiML the Twimlet generates by clicking the link.

I’ll take the Twimlet URL and pass that as the value of the url parameter in my HTTP request to Twilio.

Now when I execute my Dialog in Access, Twilio will make a call to each player’s phone number and tell them that tonight’s practice has been canceled due to weather.


And there you have it. Turning two of the most widely used pieces of software on the plane, Excel and Access, into phones is as simple as a bit of VBA code. Immensely powerful all by themselves, the ability to extend these applications with the Twilio API makes them even more so.

In this post I showed you how, using a little bit of VBA code in both Excel and Access along with the Twilio API, its trivial to both send SMS messages and initiate outbound phone calls directly from within them.

You can download the Excel and Access files I used in the demos in this post, and of course if you have any questions or comments, please hit me up on twitter or email.

  • Joe

    This is great, but when I open the Owl Roster file in Excel 2007, I don’t see a Twilioso tab. Am I missing something?

    • Devin Rader

      Hey Joe:

      Did you get promoted to enable macros when you opened the file? You’d have to agree to running the code in order to see the button.


  • Westwood Mike

    Thanks so much – this has really helped me. I wish I could tell you all the things I had to do to get it to work, but after a few days of playing with it, I finally got it to work. Changing the Excel user interface was tough — I’m using Excel 2007 and your attached Excel file was for Excel 2010. It also took me a while to realize that I have to first select the rows I want before sending the messages. Again, thank you!

    • Devin Rader

      Hey @westwoodmike:disqus: Glad you found the post useful. I’d love to hear more about what you had to do to get it working in Excel 2007. Feel free to drop me an email with the details.

  • Francisco Cruz

    Hi @devinrader:disqus . First of all, congrats for your work here with vba, it’s really helpful for amateur developers like me. I’m evaluating if I can use twilio for a friends small company, so I’m just trying to run your Access example.

    I am getting a Bad Request error, and the response I get is “The ‘To’ number 552197925610 is not a valid phone number.”. It can be easily noted that the “+” is missing (it’s a brazilian number, so it should be +55), but I’ve confirmed that it is included in the “toNumber” variable. That happened with an USA twilio number. I have tried to change my twilio number to a UK one, and then I get “The ‘To’ number +44552197925610 is not a valid phone number.”, which is not correct also. I’m using a trial account, do you think it can be related with that?

    • Devin Rader

      Hey @rfcruz:disqus, I just pushed updated versions of the sample VBA code into Github:

      Check that out and see if that code works for you. Its been updated to use a newer endpoint of the Twilio API and to do a better job catching errors. If that code still does not work for you, let me know and we can dig into further.

      • Francisco Cruz

        Hi @devinrader:disqus , thanks for your fast reply! The code is much clearer, but I get the same error. The print for the postData is:

        From=+18443254614&To=+5521979256107&Body=ola mundo

        21211The ‘To’ number 5521979256107 is not a valid phone number.

        However, it works for the calls (I got the call telling me to upgrade and then the message). I’m afraid this issue may be related with some mine misunderstanding of the Twilio account, than of the code itself. I may send you my account codes, if you think it’s useful.

        • Devin Rader

          @rfcruz:disqus, ok, just updated the code again in Github and I think I fixed the issue. The previous code was not properly encoding the phone numbers passed in the request body which meant the + sign was being dropped.

          • Francisco Cruz

            It’s rockin’! Thanks for your help @devinrader:disqus , I believe you’ll have a new costumer soon :)

            I’d like this opportunity to give you some feedback about the website. I don’t know if it’s just me, but in some cases the font is almost unreadable, because the characters are so thin and so close to each other. I’ve done a print screen and marked with red circles, you can see it here:

  • Eli Rosebud

    Thanks for the great blog. I downloaded the sample ACCESS dB and im getting a “Variable not defined” error .. the vba script editor takes me to the “set Roster” line.. can you help with that ? thanks so much

  • Dan

    This is terrific, can’t find anything else anywhere else to explain this so thanks. I am trying to add the mediaURL parameter but it never seems to recognize it. I added & “&mediaURL=” & URLEncode(“”) as a new row to the postdata, but the return debug doesn’t increase the medianum. Any ideas?

    • Devin Rader

      Hey @Dan: Thanks for trying out Twilio. Here is the code I used to add the mediaUrl parameter to the postData string:

      postData = “From=” & URLEncode(fromNumber) _
      & “&To=” & URLEncode(toNumber) _
      & “&Body=” & body _
      & “&MediaUrl=”

      All I did was add the line continuation to the “body” line and then append the MediaUrl parameter and its URL. I did not have to encode the URL.

  • Diego

    Hi, I following your steps, I can see the pluggin “Twilioso” in muy Excel 2013, but when I send the message, appear an error “Failed with error# 400 BAD REQUEST”.

    I sign up at Twilio, and your give me an AccountSID and AuthToken (Live and Test) but I tried update the AccountSID, AuthToken and FROMPHONE inside the VBA source code and appear an error “Failed with error# 400 BAD REQUEST”.

    Please can you give me a new AccountSID and AuthToken or tell me if I have another problem.



    • Devin Rader

      @disqus_8ZiwirCCy4:disqus : a couple of suggestions. First, make sure you grab the latest VBA from github:

      Second, if your still getting the error, open up the Immediate Window in the VBA editor by clicking View -> Immediate Window. The VBA code should be outputting the detailed error information there.

      Hope that helps.

  • Andres Dominicci

    Hi Devin:

    We have a client that wants an Access Database to send SMS, we are currently reviewing Twilio as one of the options. Your VBA code is super clean and easy to understand but my question is. Is it possible if i send a message saying: Reply yes if you have arrived to the customer’s site and then get that information? I’m guessing is there’s a way i will have to deal with timers but that’s not a big deal since it is not a big database or a lot of users. Thanks.

    • Devin Rader

      Hey @andresdominicci:disqus: The best way to receive the reply is to have a web server set up somewhere that Twilio can make an HTTP request to when it receives the inbound SMS.

      A second, but less scalable solution would be to use VBA to poll the Twilio REST API every few minutes to see if there are any new text messages in your logs.

      • Andres Dominicci

        I got the Send SMS working but can’t get to retrieve the log file. I’m guessing is something similar but use.

        http.Open “Get”, etc…. what would be the parameters to send and how to retrieve the logs.

        • Devin Rader

          @andresdominicci:disqus check out the Messages list resource in the REST API:

          This will return a list of messages that Twilio has sent or received.

          • Andres Dominicci

            Hi Devin:

            So i followed your advice and got everything working but there’s something going on which i can quite figure out yet. When i get the response back I don’t get all results immediately it has up to 15 minutes of delay. If i go directly into the browser and type the code sent from Access it will display all of them.

            I don’t know if it has to do with me being on trial and having a limitation on the request. I really hit a wall there. I’ve looked all over Twilio to see if this was a limitation but couldn’t find it. I hope you can give an answer. Thanks.

          • MIke S

            Hi Andres,
            How did you go receiving meaage log from Twilio on Access

          • Andres Dominicci

            I did received the logs but for some reason they never came updated with the latest information. Sometimes it took several hours to get an update from a transaction in the log. I don’t know why. I would take the url returned and manually enter it in my browser and would still get the same result. If I went through the dashboard I could see it updated. Maybe it was something I was doing wrong, I’m not sure. I wrote technical support twice and never got an answered back so we switch to another service and it has worked flawlessly.

  • T

    Hello Devin, thanks for writing this blog and the example file. I was able to get the SMS and the MakeCall to work with your newer version that includes the URLEncode. I was wondering, though, if it should be possible to access the other voice call parameters such as waiting and voice with this. Is there? Thanks!

    • Devin Rader

      Hey @T:

      In the example I use the Message Twimlet in order to provide the Twiml that Twilio executes when the outboud call is answered. Unfortunately the Simple Message twimlet does not support the options you describe, but instead of using the TwiML you could certainly set up your own web server to return whatever TwiML you want, or even just drop a static XML file on a service like Dropbox and give Twilio that URL.

  • กมล เสวตสมบูรณ์

    Great tool ! But, I have not been able to get it to work yet. Though, I will keep on trying. I am residing in Thailand. Does it work outside the US? Please advise.

  • กมล เสวตสมบูรณ์

    Devin, I opened your sample excel file. I saw a message below. Now, I am trying to figure out how to update the three constants. But, I do not how to do it. Please advise. Thank you.

    To send SMS messages from this spreadsheet, you will need to update the following constants
    in the VBA source code:




  • กมล เสวตสมบูรณ์

    OK, FROMPHONE is clear. However, how do I obtain Twilio credentials for ACCOUNTSID and AUTHTOKEN ? Please advise.

    • Devin Rader

      you can find your Account SID and AuthToken in your developer console once you log into They are labeled as your “API Credentials”.

      • กมล เสวตสมบูรณ์

        Thank you, Devin.

  • Tim

    Hey Kevin, how would one be able to select a SMS receipient using a drop down menu and have the text box populated from a selection on the excel sheet?

    • Devin Rader

      @Tim: I imaging you would have to write some more VBA code to grab a list of possible recipients from the excel sheet and use that to populate the Drop Down list. Once a user selects the recipient you could write a bit more code that goes back into the excel sheet to grab the contents of the cell that contains the message you want to send. Hope that helps.

  • lcohen


    I’ve been trying to build an Access App to send SMS messages but I’m havoing a hard time. In the blog there is a BASEURL in the vba code but I have no idea what that should be. Can anyone help me out?


  • Daniel

    Thank you! this is really helpful. Do we have a limit in how many text messages can be sent per day?

  • Nonso

    Hi Dave
    I am using your recent ms access database you uploaded

    I keep getting this error 404 not found

    What should I do?

  • J. Cash

    When using the VBA code as posted, mine fails at “http.Open “POST”, SmsUrl, False, ACCOUNTSID, AUTHTOKEN”?

    I am using it in MS Access 2016.