How to Send Bulk WhatsApp Messages with Attachments Using VBA
Question details
The user wants to automate sending bulk WhatsApp messages with image or PDF attachments using VBA, while seamlessly skipping contacts that do not have active WhatsApp accounts.

- Product
- Spreadsheets
- Device & OS
- not provided
- Scenario
- Automating bulk messaging workflows via WhatsApp Web or the Desktop app directly from a spreadsheet.
- Observed behavior
- The macro stops running or becomes misconfigured when it encounters a mobile number that is not registered on WhatsApp.
Ensure you have the WhatsApp Desktop application installed and logged in. Verify that your spreadsheet contains a clean list of contact numbers formatted with their respective international country codes.
Use VBA Error Handling to Skip Invalid WhatsApp Numbers
Implement an 'If' condition and 'GoTo' label within your VBA loop to bypass numbers that fail or are blank, ensuring the macro continues without stopping.
Because VBA cannot natively verify whether a phone number is registered on WhatsApp before attempting to send a message, the best approach is to manage the loop logic. By validating the cell data and handling potential UI timeouts or errors, you can force the macro to skip to the next row.
Set up a 'For' or 'Do While' loop in your VBA script to iterate through the spreadsheet rows containing the phone numbers and file attachment paths.
Insert an 'If' statement at the beginning of the loop to check if the number cell is empty or invalid (e.g., If Cells(i, 1).Value = "" Then GoTo NextRecord).
Use 'On Error Resume Next' or specific error trapping around the WhatsApp interaction code to prevent the macro from halting when WhatsApp fails to locate the contact.
Place the label 'NextRecord:' directly before your 'Next i' or 'Loop' statement so the script knows where to jump when it needs to skip a contact.

Automate Workflows with WPS Office Macros
WPS Office provides robust support for VBA and Macros, allowing you to run your WhatsApp automation scripts seamlessly while enjoying a highly compatible and lightweight spreadsheet environment.
- 1. Open your spreadsheet: Launch WPS Spreadsheets and open the file containing your contact list and VBA code.
- 2. Access Developer tools: Navigate to the 'Tools' tab on the top ribbon and select 'Developer' to access macro features.
- 3. Run the VBA script: Click 'Visual Basic Editor' to view, paste, or execute your bulk WhatsApp messaging script.

Frequently Asked Questions
Why does my VBA script stop when a number isn't on WhatsApp?
When the script attempts to interact with the WhatsApp application for an unregistered number, it encounters an unexpected UI state or popup indicating the number is invalid. Without proper error handling or 'GoTo' skip logic, this unexpected state causes the macro to crash or halt.
Can I send both images and PDFs using this VBA method?
Yes. By generating the appropriate file paths in your spreadsheet and passing them to your WhatsApp attachment sequence (usually via SendKeys, UI automation, or clipboard pasting), you can attach both images and PDFs within the same loop.
Do I need the WhatsApp Desktop app or WhatsApp Web for this to work?
Most VBA scripts for this purpose rely on opening a specific URL (like wa.me) via a shell command, which then triggers the WhatsApp Desktop app. Having the native desktop app installed and logged in usually provides a much more stable automation experience compared to browser-based WhatsApp Web.




