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

Whatsapp Vba Macro

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
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