0% found this document useful (0 votes)
687 views2 pages

Whatsapp Vba Macro

The document provides a VBA code to automatically send a WhatsApp message with an image. The code defines variables to store the message text, image directory and name. It then copies the image to the clipboard and navigates to the WhatsApp web page to send the message and image by simulating key presses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
687 views2 pages

Whatsapp Vba Macro

The document provides a VBA code to automatically send a WhatsApp message with an image. The code defines variables to store the message text, image directory and name. It then copies the image to the clipboard and navigates to the WhatsApp web page to send the message and image by simulating key presses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

How to automatically send message with image via Whatsapp using VBA.

Here's the complete VBA code:


Option Explicit

Sub SendMessageWithPicViaWhatsapp()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
Dim mytext As String
Dim myDir As String
mytext = Sheet1.Range("C2")

Dim myObj
Dim Pictur

Set myObj = ActiveSheet.DrawingObjects


For Each Pictur In myObj
If Left(Pictur.Name, 7) = "Picture" Then
Pictur.Select
Pictur.Delete
End If
Next

Dim EmployeeName As String, T As String

myDir = "C:\Users\takyar\Pictures\employees\"
EmployeeName = Range("A2") & Range("B2")
T = ".jpg"

On Error GoTo errormessage:

EmployeeName = Range("A2") & Range("B2")

ActiveSheet.Shapes.AddPicture Filename:=myDir & EmployeeName & T,


linktofile:=msoFalse, _
savewithdocument:=msoTrue, Left:=240, Top:=15, Width:=60, Height:=60

errormessage:
If Err.Number = 1004 Then
MsgBox "File does not exist." & vbCrLf & "Check the name of the employee!"
Range("A2").Value = ""
Range("B2").Value = ""
End If

ActiveSheet.Shapes(1).Copy

ie.navigate "https://web.whatsapp.com/send?phone=9..." & mytext

Application.Wait (Now + TimeValue("00:00:10"))

Call SendKeys("^v")
Call SendKeys("{ENTER}", True)
Application.Wait (Now + TimeValue("00:00:05"))
Call SendKeys("{ENTER}", True)

End Sub

You might also like