Created
April 9, 2024 09:18
-
-
Save kuatroestrellas/0f3e8850d1215ede9a4ace469de0f892 to your computer and use it in GitHub Desktop.
send message from excel to whatsapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Worksheet_Change(ByVal Target As Range) | |
Dim KeyCells As Range | |
Dim URL As String | |
Dim HTTPRequest As Object | |
Dim ResponseData As String | |
Dim Texto As String | |
Dim Estado As String | |
Dim Telefono As String | |
Dim ApiKey As String | |
' Definir el rango de celdas que activará el evento (columna B) | |
Set KeyCells = Me.Range("B:B") | |
' Verificar si el cambio ocurrió en el rango de celdas especificado | |
If Not Application.Intersect(KeyCells, Target) Is Nothing Then | |
' Verificar si el valor en la columna B es "1" | |
Estado = Target.Value | |
If Estado = "1" Then | |
' Obtener el texto de la columna A de la misma fila | |
Texto = Me.Cells(Target.Row, "A").Value | |
' Obtener el número de teléfono y la API Key de la Hoja 2 | |
Telefono = Sheets("Hoja2").Range("B3").Value | |
ApiKey = Sheets("Hoja2").Range("B4").Value | |
' Definir la URL del webhook con el número de teléfono y la API Key | |
URL = "https://api.callmebot.com/whatsapp.php?phone=" & Telefono & "&text=" & Replace(Texto, " ", "+") & "&apikey=" & ApiKey | |
' Crear una instancia de un objeto XMLHTTP | |
Set HTTPRequest = CreateObject("MSXML2.XMLHTTP") | |
' Realizar la solicitud GET al webhook | |
HTTPRequest.Open "GET", URL, False | |
HTTPRequest.send | |
' Obtener la respuesta (puedes manejar la respuesta como desees) | |
ResponseData = HTTPRequest.responseText | |
' Opcional: mostrar un mensaje o hacer otras acciones según la respuesta | |
MsgBox "Mensaje enviado al webhook." | |
End If | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment