Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Articles

Send WhatsApp messages from Excel using VBA

To send WhatsApp messages from Excel using VBA, you can use the

WhatsApp API
to send messages via a web link. Here's how you can do it:


### Steps:
1. **Prepare your Excel sheet:**
   - Ensure you have a column with phone numbers formatted correctly (including the country code without any special characters like `+` or `-`).
   - Prepare another column with the message you want to send.

2. **Add VBA Code:**
   - Open the VBA editor by pressing `Alt + F11`.
   - Insert a new module: `Insert > Module`.
   - Paste the following VBA code:

```vba
Sub SendWhatsAppMessages()
    Dim LastRow As Long
    Dim ws As Worksheet
    Dim phoneNumber As String
    Dim message As String
    Dim WhatsAppLink As String
    
    ' Set the worksheet containing the data
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change Sheet1 to your sheet name

    ' Find the last row with data in column A (assuming phone numbers are in column A)
    LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ' Loop through each row to get the phone number and message
    For i = 2 To LastRow
        phoneNumber = ws.Cells(i, 1).Value ' Assuming phone numbers are in column A
        message = ws.Cells(i, 2).Value ' Assuming messages are in column B
        
        ' Encode the message to be URL-friendly
        message = Application.WorksheetFunction.EncodeURL(message)
        
        ' Create the WhatsApp API link
        WhatsAppLink = "https://api.whatsapp.com/send?phone=" & phoneNumber & "&text=" & message
        
        ' Open the WhatsApp link in the default web browser
        ThisWorkbook.FollowHyperlink WhatsAppLink

        ' Pause for 2 seconds to allow the WhatsApp web page to load (adjust as necessary)
        Application.Wait (Now + TimeValue("00:00:02"))
    Next i
End Sub
```

### How It Works:
- **Phone Number:** The code assumes phone numbers are in column `A`. They must be in the format `countrycodephonenumber` (e.g., `911234567890` for India).
- **Message:** The code assumes the message text is in column `B`.
- **WhatsApp API Link:** The code uses `https://api.whatsapp.com/send?phone=` to initiate a WhatsApp chat.

### Running the Macro:
- Go back to Excel and run the macro `SendWhatsAppMessages` from `Developer > Macros`.
- Excel will open your default browser for each phone number with the message ready to be sent via WhatsApp Web.

### Notes:
- Ensure WhatsApp Web is logged in your browser.
- This method requires user interaction to hit "Send" in the browser.
- You can adjust the wait time if your internet connection is slower or faster.

This method is a straightforward way to send WhatsApp messages via Excel without any third-party tools.

caa August 29 2024 147 reads 0 comments Print

0 comments

Leave a Comment

Please Login to Post a Comment.
  • No Comments have been Posted.

Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 3
Members Online 0

Total Members: 11
Newest Member: Jhilam