When I try sending multiple line message it will send each line separately. How I can send whole message one time. This is my code
Sub WhatsAppMessage()
'Activate Selenuim web driver
Dim bot As New WebDriver
Dim ks As New Keys
Dim mob As String
Dim text As String
'Init new Chrome Instance & navigate to webwhatsapp
bot.Start "Chrome", "https://web.whatsapp.com/"
bot.Get "/"
'Ask user to scan the QR code. Once Logged in, continue with the macro
'MsgBox "Please Scan QR code, After you are Logged in, please confirm this message box by clicking OK"
'Determine number of messages by identifying the number of last rows in column A
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
'Search mobile number / name, Press enter, paste text into whatsapp, press enter to send message
For i = 4 To LastRow
'Get mobile number or name from worksheet
mob = Sheets("Data").Cells(i, 1).Value
'Get Message from Worksheet
text = Sheets("Data").Cells(2, 1).Value
'click in the searchBox
bot.FindElementByXPath("//*[@id='side']/div[1]/div/div/div[2]").Click
'wait 500ms
bot.Wait (500)
'Insert mobile number or name
bot.SendKeys (mob)
'wait 500ms
bot.Wait (500)
'press enter to confirm search mobile
bot.SendKeys (ks.Enter)
'wait 500ms
bot.Wait (500)
'Load message in to web whatsapp
bot.SendKeys (text)
'wait 500ms
bot.Wait (500)
'press enter to send message
bot.SendKeys (ks.Enter)
Next i
MsgBox "Done :)"
End Sub
This is the message which I want to send at one time but it will send each line separately
Hello!!
Dear Shree Deeplaxmi Customers,
Exclusive Once in a Year Sale Event - Up to 50% Off! Limited Stock!Join us for an incredible sale starting from July 16, 2023.
Enjoy discounts from 15% to 50% on a wide range of products!
Hurry and take advantage of this limited-time offer. Stock is limited, and once it's gone, the sale ends. Don't miss out on the opportunity to grab your desired items at unbeatable prices.Visit our store soon and make the most of this exclusive discount.
We look forward to serving you and providing an exceptional shopping experience.See you at our sale event!
Best regards,
Sandeep Sakunde
Shree Deeplaxmi Readymade
For anyone reading this, promise me you won't be using this to spam people, ok? Alright...
I've never used WhatsApp, but it's very common for messaging apps to interpret ENTER as "SUBMIT".
Here, Selenium is just naively imitating what you would do on your keyboard to reproduce the text provided and sending ENTER when it encounters a linebreak. I'm assuming that, like most messaging apps, WhatsApp supports linebreaks inside messages, but you have to press SHIFT+ENTER to avoid sending the message right away.
To do that with Selenium, you could split line-by-line into an array, type the line one at a time and send SHIFT+ENTER at the end of each like. Eg.:
Here's a the complete demo using jsfiddle:
Note that a simple
Replace(text, vbNewLine, keyObj.Shift & keyObj.Enter)won't work because the shift key is sticky, hence, starting from the second line, all your text will be uppercase.Related questions: