Send WhatsApp Messages From Excel With VBA Using Twilio | Step-by-Step Tutorial 💬
Vložit
- čas přidán 4. 06. 2024
- 🔥 PLEASE NOTE 🔥
According to Twilio, please be aware that the Twilio Sandbox for WhatsApp is meant for testing and discovery purposes only.
The Sandbox expires three (3) days after joining. After this time, you need to re-join (by re-sending the 'code' to Twilio's number) to continue testing.
More details can be found here:
www.twilio.com/docs/whatsapp/...
___________________________________________________
In this tutorial, I will show you, how you can send WhatsApp messages directly from Microsoft Excel with VBA.
We will build a POST Request to Twilio’s API using VBA.
✅ Chapters:
0:00 Demo
0:31 Get ready with Twilio
3:50 VBA Code
10:01 Outro
👉 Download the Excel template here: pythonandvba.com/twilio-whatsapp
🤷♂️ If you have questions or encounter any errors, please feel free to post them in the comments section. I would be glad to answer your queries when time permits.
🚩 VBA CODE:
___________________________________________________
Sub WhatsApp()
'Authentication
ACCOUNTSID = "YOUR ACCOUNT SID" '-- REPLACE ME
AUTHTOKEN = YOUR AUTH TOKEN" '-- REPLACE ME
'Variables
fromNumber = "%2B14155238886"
toNumber = "RECEIVER NUMBER" '-- REPLACE ME
BodyText = "YOUR MESSAGE TEXT" '-- REPLACE ME
'Use XML HTTP
Set Request = CreateObject("MSXML2.ServerXMLHTTP.6.0")
'Specify URL
Url = "api.twilio.com/2010-04-01/Acc..." & ACCOUNTSID & "/Messages.json"
'Post URL with authentication
Request.Open "POST", Url, False, ACCOUNTSID, AUTHTOKEN
'Request Header
Request.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'Concatenate PostData
postData = "From=whatsapp:" & fromNumber & "&To=whatsapp:%2B" & toNumber & "&Body=" & BodyText
'Send the Post Data
Request.send postData
'[OPTIONAL] Get response text (result)
MsgBox Request.responseText
End Sub
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
𝗖𝗢𝗡𝗡𝗘𝗖𝗧 𝗪𝗜𝗧𝗛 𝗠𝗘:
🌎 Website: pythonandvba.com
📝 GitHub: github.com/Sven-Bo
⭐ Discord: pythonandvba.com/discord
▶️ Subscribe: czcams.com/users/CodingIsFun?sub...
🎉 𝗙𝗥𝗘𝗘 𝗘𝘅𝗰𝗲𝗹 𝗔𝗱𝗱-𝗶𝗻 𝘁𝗼 𝗯𝗼𝗼𝘀𝘁 𝘆𝗼𝘂𝗿 𝗽𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝘃𝗶𝘁𝘆
Get it here: pythonandvba.com/mytoolbelt
📚 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗳𝗼𝗿 𝗹𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗩𝗕𝗔 & 𝗣𝘆𝘁𝗵𝗼𝗻
Check out my recommendations: pythonandvba.com/resources
☕ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲❓
If you want to support this channel, you can buy me a coffee here:
pythonandvba.com/coffee-donation
That's awesome! You are such a contributor to the VBA world. I really love your channel. Keep going mate!
Thank you ver much! Glad you are enjoying the videos
Great video, it's very well done!
Now I'm interested in sending also images.
Thank you again!
Hi Gabriele,
Thank you very much.
Besides Twilio, there is also another method on how to send WhatsApp messages in Excel using VBA (& Selenium).
If you are interested, kindly have a look at my tutorial:
👉 czcams.com/video/Wn9L1MD_y0Y/video.html
In the tutorial, I am not going to show how to send images, but I added this feature in the following Workbook:
👉 bit.ly/2LIfHO6
Hope that helps.
Cheers,
Sven
Hi Sven! Sorry for the late reply.
I watched your video "WhatsApp messages in Excel using VBA (& Selenium)" and tried to make my Excel program. Besides, I was inspired by this other video czcams.com/video/3klMEX40fwg/video.html for the image sending part. So I write this lines of code in VBA to send images and it works:
"'Click on Image icon
bot.FindElementByXPath("//input[@accept='image/*,video/mp4,video/3gpp,video/quicktime']").SendKeys (imagePath)
bot.Wait 2000
bot.FindElementByXPath("//span[@data-icon = 'send']").Click"
Today I watched your video "Send Bulk Messages/Images/Videos/Documents from Excel [Free Tool / Software]" and it's super interesting!
Many thanks!
Cheers,
GB
@@gabrielebasaglia5063 Hi Gabriele,
Thank you very much for your feedback. Your solution sounds great - well done!
Cheers,
Sven
Thank you so much! this has really helped me
My pleasure, thank you for watching!
Great cool idea thanks for video
Glad you enjoyed the video.
Great Content.
Thank you!
Wow this is really helpful !! Is there a way we can stop the auto closing chrome once the task is done
Thank you for watching the video. Actually, in this video, we did not automate the chrome browser.
Hi, I'm building an excel file to help me do the basic office tasks for my small business. I would like to send a picture from excel to a specific group in WhatsApp. the picture will be a print of one of the excel sheets. it will always be the same group and the same sheet which will be sent. I looked at both your videos of excel interacting with WhatsApp (Twilio and Selenium) and would like to ask will one of them could make that job? with the proper changes of course...
And, your videos are really helpful, thank you very much for the time spent... !
Hi there,
Thank you for watching the video.
My approach would be as follows:
1) Use the following version: czcams.com/video/lt2xhww_wcE/video.html
2) Select as the 'Send Method': Searchbox
3) Enter the WhatsApp GroupName in column A
4) In Column B, enter the file path to the Image. (take the screenshot of the Daily Excel File and save it under the file name again)
[Optional] You could automate taking & saving the screenshot of the specific Excel range using VBA as well
Hope it helps!
Cheers,
Sven ✌
@@CodingIsFun What are the limitations of this metod:
a. Can i change it and send picture with it?
b. Can i send to a group and not just specific contact?
Thanks
@@CodingIsFun i just download this version a week ago , but now the video is taken down by youtube,
btw i also have a question, why the delay setting said it's in seconds, while the reality it's work in Minutes? i try to input "3" and the delay between the message is 3 minutes, then i tried again input "2" , the delayed time now changing into 2 minutes.
so is it work in minutes? not seconds?
(I don't want to type phone numbers again and again) if you upload a video for 10 or 20 numbers we will put in excel and it will send messeges to all numbers with one click(messege would one by one or all at the same time)? For 20 or more numbers
Hi,
you could do that with a "for loop" for instance.
Here is a template I have created for you:
bit.ly/38nXzC6
Please keep in mind, with the free trial from Twilio, EVERY number needs to be registered beforehand.
Hi,
I just wanted to inform you, that I have created an alternative solution using VBA & Web automation to send WhatsApp Bulk Messages in Excel for free.
You can find the video here:
👉 czcams.com/video/Wn9L1MD_y0Y/video.html
Hope this solution works for you 🙏
I am getting error and I would just like to ask do I substitute " & ACCOUNTSID & "_from the section that you have commented specifyURL then do I also substitute ACCOUNTSID, AUTHTOKEN in the section for 'Post URL with authentication- with my own values??? thank u for the video
*Thanks for watching the video* What does the error message say?
You only need to replace it once here:
'Authentication
ACCOUNTSID = "YOUR ACCOUNT SID" '-- REPLACE ME
AUTHTOKEN = YOUR AUTH TOKEN" '-- REPLACE ME
@@CodingIsFun {"code":20003,"detail":"Your AccountSid or AuthToken was incorrect."," message": "Aunthetication error_invalidusername","moreinfo":"www.twilio.com/docs/errors/20003","status":401}
@@whoodiniiam Thank you. Indeed it seems to be an authentication problem. Could you kindly check that you have entered a valid Authtoken & Accountsid? Thank you :)
Nice helpful and informative video....TQ....Please make video for WA Group all contact save in Excel.
Thank you very much for your comment & video suggestion 😃
hello, how can we do this through whatsapp sender? after purchasing the premium. I am getting stuck there please help
Thanks for watching. Sorry, but I am not sure what you mean or what exactly you are looking for. Cheers, Sven ✌️
Hi you have any attendance system code? Which built in python ?
No, I do not have - sorry! 😕
@@CodingIsFun anything regarding education/school college?
i keep getting "runtime error 429 activeX component can't create object. how can i fix this
Thank you for watching the video. Could you please try out the following solution?
czcams.com/video/iW9PqsbwDc8/video.html
I hope it helps!
Hey thanks so much for the code , but I am getting an error "Invalid TLS version,Upgrade required"...Please help
Hi. Which operating system are you using? Windows 10?
@@CodingIsFun windows 7
I was googling a solution for this error. A potential fix might be this one here: support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi
@@CodingIsFunI tried with windows 10 and it worked like magic!!...thank you once again..
I have a couple of questions though..
1.how can i post a message to a group ?
2. how long will twilio trial account work because I realised that I was not getting charged from the credit balance of my trial account.
.
@@jolalla1 Glad it is working for you.
In regards to your questions:
1. As for my understanding, sending messages to GroupChats is not (yet) supported.
2. The sandbox is completely free. However, the Sandbox expires three (3) days after joining. After this time, you need to re-join (by re-sending the 'code' to Twilio's number) to continue using the Sandbox.
How can we add pictures or pdfs together with the messages?
Thanks for watching the video. I have not implemented it, but it is also possible:
www.twilio.com/blog/whatsapp-media-support
You need to add the following to the 'postData'-string, which will be sent via the Post request:
"MediaUrl=demo.twilio.com/owl.png"
I hope this helps!
Hi, I can't get it to work.
This error shows up, could you help me?
{code": 20404, "message": "The requested resource 12010-04-01/Accounts/STWILIO_ACCOUNT_SID/Messages.json was not found", "more_info": "www.twilio.com/docs/errors/20404", "status": 404)
Hi there,
Could you kindly check if your URL variable looks like this one [Link to screenshot]:
👉 prnt.sc/wgfrlm
By the way, I have also another solution on how to send WhatsApp Messages via VBA [Link to video]:
👉 czcams.com/video/Wn9L1MD_y0Y/video.html
Please let me know if you need further support.
Cheers,
Sven
That's awesome!
but Is there another way to send messages to phone numbers that I don't know (not my friends)
because I can't tell them to send "join sense-lady" code to the twilio number???
Unfortunately, WhatsApp offers its API only to businesses.
Other workarounds would involve Web automation using the online interface [web.whatsapp.com], e.g. using VBA Selenium.
However, in my opinion, I find this kind of web automation also not ideal.
@@CodingIsFun yes you're right, web automation is not ideal.
Can I use Whatsapp API as a normal person, is there any chance to me??
and if I use web automation, is there any way to ensure that the message is sent usign Excel VBA code????
thank you very much
@@moodraatu8733
The requirements to use the WhatsApp API are listed down here:
👉 developers.facebook.com/docs/whatsapp/getting-started/?locale=en_US
There are actually many ways on how you could achieve this in Excel VBA.
My prefered solution would be to use VBA Selenium.
In the past I have uploaded a video on how to use VBA Selenium to retrieve stock information:
👉 czcams.com/video/HZU2OtDa2eI/video.html&ab_channel=CodingIsFun
Once you got familiar with Selenium, you could also automate/send WebWhatsApp using VBA.
However, it would be a semi-automated solution as every time you would be asked to scan the QR Code in order to log-in.
I shortly wrote a "starter-code", if you want to give it a try with Selenium:
[You need to have VBA Selenium installed on your machine, as well as the current Chrome Webdriver, to run the code below]
🚩 VBA CODE:
Sub WebWhatsApp()
Dim bot As New WebDriver
'Init New Chrome instance
bot.Start "chrome", "web.whatsapp.com/"
bot.Get "/"
MsgBox "Please scan the QR Code. After you are logged in, please confirm this MessageBox by clicking 'Ok'"
' ...open conversation
' ...send message
End Sub
Sorry, that I cannot help you further.
Cheers,
Sven
@@CodingIsFun thank you so much I really appreciated
Is this code you wrote a good to send hundreds of messages to hundreds of number phones?
🔥 PLEASE NOTE 🔥
According to Twilio, please be aware that the Twilio Sandbox for WhatsApp is meant for testing and discovery purposes only.
The Sandbox expires three (3) days after joining. After this time, you need to re-join (by re-sending the 'code' to Twilio's number) to continue testing/sending WhatsApp messages.
👉 More details can be found here:
www.twilio.com/docs/whatsapp/sandbox
Its awesome but if we will use twilio then receiver will not get our number they are getting twilio's number and how much twilio's price if i planned to purchase
Sir reply
Hi.
Thank you for your feedback 🙏
I totally agree with you. The solution is not ideal.
In regards to the pricing, I would kindly refer you to the official Twilio pricing overview:
www.twilio.com/whatsapp/pricing/us
@@saddamskst Hi,
I just wanted to inform you, that I have created an alternative solution using VBA & Web automation to send WhatsApp Bulk Messages in Excel for free.
You can find the video here:
👉 czcams.com/video/Wn9L1MD_y0Y/video.html
Hope this solution works for you 🙏
If we are using a business WhatsApp, is there still a need for this
Thank you for watching the video & your question.
It depends on your use case. Kindly have a look at the following article, which explains the difference between WhatsApp, WhatsApp Business, and WhatsApp Business API:
www.telemessage.com/difference-between-whatsapp-whatsapp-business-and-whatsapp-business-api/
The main advantage of using an API is that you send programmatically multiple WA messages.
I hope this helps!
Hi i have 2 queries;
1. How do we attach videos, pictures or documents i.e pdf
2. Is there way we can use Google sheet or app script so as it becomes automatic?
Thanks for watching.
1. You need to adjust the code and pass an additional parameter to the API call, 'MediaUrl'. Please see below the documentation:
support.twilio.com/hc/en-us/articles/360017961894-Sending-and-Receiving-Media-with-WhatsApp-Messaging-on-Twilio
2. I am not familiar with Google Sheet / App script, so I cannot answer that question.
Good job but i have still an error.. Error run time 2147012889 (80072ee7). What i have to do ?
*Thank you for watching the video*
Could you let me know what line in the VBA is code is highlighted after clicking "Debug" on the error message?
Additionally, does the error message say "The Server Name or Address can not be resolved "?
*BTW* I also have another tutorial on how to send WhatsApp messages directly from Excel (instead of using Twilio). Perhaps it might be interesting for you:
👉 czcams.com/video/Wn9L1MD_y0Y/video.html
Cheers,
Sven ✌
I downloaded template and do all process but not working pls help
Thanks for watching. Unfortunately, with that bit of information, I cannot help you. You might want to take some time to write down which line of code is causing the error; let me know if you have modified the code from the tutorial, explain in more depth what you did to troubleshoot the problem and provide some more context. Thanks!
voce pode me enviar o primeiro video que fez sobre o whatsapp?
pythonandvba.com/whatsappsender
@@CodingIsFun seu site é otimo, novamente parabéns!!!!!
What happened to the video with the automated excel that sends whatsapp messages?
I am sorry, but YT deleted the video 😥
@@CodingIsFun maybe you can upload in a different name, or change the video a bit and add again. It was very useful.
@@CodingIsFun Sorry to hear that
How can I send a single msg to multiple numbers using this??
Thank you for watching the video. I have created the following solution for this:
👉 Excel template for sending a message to multiple numbers [Google Drive]: bit.ly/38nXzC6
@@CodingIsFun hey i saw your file but how it works??
@@riyazshroff1875 By time, I will make a dedicated tutorial about it. You would just need to input your number in Column A and select 'Text' if you want to send a text message. Once done, click the send button. If you download the file, I have inputted some sample messages. Kindly try it out :)
first This is a free trial account
Second you can only send to your phone
Basically This is not working
Thank you comment.
Yes, this is true. This method definitely comes with a lot of limitations.
An alternative approach would be to automate the WebWhatsApp Interface via Excel VBA.
Here is the video I have created to show you an alternative solution on how to send WhatsApp Messages from Excel:
👉 czcams.com/video/Wn9L1MD_y0Y/video.html&ab_channel=CodingIsFun
@codingisfun how I can sent attachment to multiple WhatsApp contacts.