0

Hi guys i am trying to follow this https://www.youtube.com/watch?v=Wn9L1MD_y0Y&t=107s on how to automate whatsapp with VBA.

This is the whole code.

Sub WebWhatsApp()

'Activate Selenium Type Library: Tools > Reference

Dim bot As New WebDriver
Dim ks As New Keys

'Init New Chrome instance & navigate to WebWhatsApp
bot.Start "chrome", "http://web.whatsapp.com/"
bot.Get "/"

'Ask user to scan the QR code. Once logged in, continue with macro
MsgBox "Please scan the QR code. After you are logged in, please confirm this message box by clicking"

'Determinate number of messages by identifying the number of last rows in column A
lastrow = Cells(Rows.Count, 1).End(x1Up).Row

'Search phonenumber/name, press enter, paste text into WebWhatsApp, press Enter to send message

For i = 2 To lastrow
    'Get search text (phone number or name) from worksheet
    searchtext = Sheets(1).Range("A" & i).Value

    'Get textmessage from worksheet
    textmessage = Sheets(1).Range("B" & i).Value

    'click in the searchbox"
    bot.FindElementByXPath("//*[@id="side"]/div[1]/div/label/div/div[2]").Click
    
    
    'Wait 500 ms
    bot.Wait (500)

    'Insert search text(phone number or name)
    bot.SendKeys (searchtext)

    'Wait 500 ms
    bot.Wait (500)

    'Press Enter to confirm search text
    bot.SendKeys (ks.Enter)

    'Wait 500 ms
    bot.Wait (500)

    'Load message into WebWhatsApp
    bot.SendKeys (textmessage)

    'Wait 500 ms
    bot.Wait (500)

    'Press Enter to send the message
    bot.SendKeys (ks.Enter)

Next i

'Get notification once done,
MsgBox "Done :)"


End Sub

Apparently i had an error from

    bot.FindElementByXPath("//*[@id="side"]/div[1]/div/label/div/div[2]").Click

It states Compile error : Syntax error

Can Anyone tell me why? I have followed the instructions and codes clearly.

2 Answers 2

1

The problem is the double quotes around side.

To fix the problem either replace them with single quotes:

    'click in the searchbox"
    bot.FindElementByXPath("//*[@id='side']/div[1]/div/label/div/div[2]").Click

or double them up.

    'click in the searchbox"
    bot.FindElementByXPath("//*[@id=""side""]/div[1]/div/label/div/div[2]").Click
Sign up to request clarification or add additional context in comments.

3 Comments

What about single quotes? You may have to triple quote or concatenate in parts: "//*[@id=" & """" & "side" & """" & "]/div[1]/div/label/div/div[2]". Feel free to play around as VBA compiles after editing the ine.
okay thanks! Now I have another error. lastrow = Cells(Rows.Count , 1).End(x1UP.Row) There's a Run time error '1004' : Application-defined or object-defined error
It should be End(xlUp).Row not End(x1UP.Row). Note, you can avoid this type of error by adding Option Explicit at the top of the module.
0

change to :

//*[@id='side']/div[1]/div/div/div[2]/div/div[2]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.