Sending a message from VBA to a whatsapp number - vba

I am using the following code to try and send a Whatsapp message from VBA Excel.
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application") 'Create object IE
IE.navigate "whatsapp://send?phone=5511912341234&text=something" 'Send message "something" to this phone (Brazil)
Application.Wait Now() + TimeSerial(0, 0, 3) 'ok just one wait and sendkeys :v
SendKeys "~"
'IE.Quit 'The navigate already kills the IE
Set IE = Nothing 'Clear the object
End Sub
Its calling up the Whatsapp application but is not pasting the message - it just waits for a message to be typed in. Have they changed the format?

Related

vba code for sending texts from excel to whatsapp

I have previously used selenium webdriver for sending messages to whatsapp via VBA. But now, I need some pure vba codes to send text from excel sheet. What I discovered InternetExplorer does not support whatsapweb. I searched the internet I discovered some tutorial where it uses APPACTIVATE method for using CHROME.
AppActivate "Chrome"
But I was not able to use chrome with this code. Can anyone help with code below/ suggesting links will also be benefital for sending messages through vba to whatsapp without third party applications.
Sub Automate_IE_Load_Page()
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
URL = "https://web.whatsapp.com/"
'Navigate to URL
IE.navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
Do While IE.readyState = 4: DoEvents: Loop 'Do While
Do Until IE.readyState = 4: DoEvents: Loop 'Do Until
'Webpage Loaded
Application.StatusBar = URL & " Loaded"
'Unload IE
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
On internet I saw excel formula where it hyperlinks the text message to whatsapp from formula bar, but HYPERLINK formula opens the edge browser not IE. Could not I use also Edge browser in vba library instead IE.Application?
=IF(G3="","",HYPERLINK("https://web.whatsapp.com/send?phone=%2B"&VLOOKUP(B3,'Employee Master'!A:D,4,0)&"&text=" & H3&"&app_absent=1&send=1",")"))

Web scraping debug print LocationURL returns unexpected value

This code is supposed to print webpage URL into the immediate window.
Sub BrowseToSite()
Dim IEObject As InternetExplorer
'Creating new instance of the internet explorer application
Set IEObject = New InternetExplorer
'make IE app visible
IEObject.Visible = True
'navigate to URL
IEObject.Navigate URL:="https://www.youtube.com"
Do While IEObject.Busy = True Or IEObject.ReadyState <> READYSTATE_COMPLETE
Application.Wait Now + TimeValue("00:00:01")
Loop
'Print the URL that we are currently at
Debug.Print IEObject.LocationURL
End Sub
I expect https://www.youtube.com but I get res://ieframe.dll/navcancl.htm.
I have references set to Microsoft HTML Object Library and Microsoft internet controls.

How to pause Excel VBA and wait for user interaction before loop

I have a VERY basic script I am using with an excel spreadsheet to populate a form. It inserts data into the fields then waits for me to click the submit button on each page. Then it waits for the page to load and fills in the next set of fields. I click submit, next page loads, etc. Finally, on the last two pages I have to do some manual input that I can't do with the spreadsheet. Code thus far is shown below.
My question is, at the end of what I have there now, how can I make the system wait for me to fill out that last page, then once I submit it realize that it has been submitted and loop back to the beginning, incrementing the row on the spreadsheet so that we can start over and do the whole thing again for the next student?
As you will probably be able to tell I am not a programmer, just a music teacher who does not savor the idea of filling out these forms manually for all 200 of my students and got the majority of the code you see from a tutorial.
Function FillInternetForm()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
'create new instance of IE. use reference to return current open IE if
'you want to use open IE window. Easiest way I know of is via title bar.
IE.Navigate "https://account.makemusic.com/Account/Create/?ReturnUrl=/OpenId/VerifyGradebookRequest"
'go to web page listed inside quotes
IE.Visible = True
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
IE.Document.All("BirthMonth").Value = "1"
IE.Document.All("BirthYear").Value = "2000"
IE.Document.All("Email").Value = ThisWorkbook.Sheets("queryRNstudents").Range("f2")
IE.Document.All("Password").Value = ThisWorkbook.Sheets("queryRNstudents").Range("e2")
IE.Document.All("PasswordConfirm").Value = ThisWorkbook.Sheets("queryRNstudents").Range("e2")
IE.Document.All("Country").Value = "USA"
IE.Document.All("responseButtonsDiv").Click
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
IE.Document.All("FirstName").Value = ThisWorkbook.Sheets("queryRNstudents").Range("a2")
IE.Document.All("LastName").Value = ThisWorkbook.Sheets("queryRNstudents").Range("b2")
IE.Document.All("Address1").Value = "123 Nowhere St"
IE.Document.All("City").Value = "Des Moines"
IE.Document.All("StateProvince").Value = "IA"
IE.Document.All("ZipPostalCode").Value = "50318"
End Function
I would use the events of the IE, more specifically the form, something like this, using MSHTML Controls library.
Private WithEvents IEForm As MSHTML.HTMLFormElement
Public Sub InternetExplorerTest()
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Set ie = New SHDocVw.InternetExplorer
ie.Visible = 1
ie.navigate "http://stackoverflow.com/questions/tagged/vba"
While ie.readyState <> READYSTATE_COMPLETE Or ie.Busy
DoEvents
Wend
Set doc = ie.document
Set IEForm = doc.forms(0)
End Sub
Private Function IEForm_onsubmit() As Boolean
MsgBox "Form Submitted"
End Function

using VBA to interact with webpages

I've found some code online to use VBA to interact with Webpages and have since tweaked it. I'm trying to auto login to a website, then pull some reports...
Here's the code I have so far..
Private Sub IE_Automation()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncomment Next line To see form results
IE.Visible = True
' Send the form data To URL As POST binary request
IE.Navigate "https://e-oscar-web.net/EntryController?trigger=Login"
' Statusbar
'Application.StatusBar = "www.e-Oscar.com is loading. Please wait..."
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now())
Loop
Set objCollection = IE.document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If objCollection(i).ID = "companyId" Then
' Set text for search
objCollection(i).Value = "compId"
Else
If objCollection(i).ID = "userId" Then
objCollection(i).Value = "uId"
Else
If objCollection(i).ID = "password" Then
objCollection(i).Value = "pwd"
Else
If objCollection(i).ID = "securityMsgAck1" Then
objCollection(i).Value = True
'Else
'If objCollection(i).Type = "button" Then
'objCollection(i).Value = True
' "Search" button is found
Set objElement = objCollection(i)
End If
End If
End If
End If
'End If
i = i + 1
Wend
objElement.Click ' click button to search
' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
' Show IE
IE.Visible = True
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
Application.StatusBar = ""
End Sub
This seems to be working fine. It pulls the webpage up, fills out the three input boxes, then appears to "check" the radio button that I've acknowledged the terms and agreements, but when I uncomment out
'Else
'If objCollection(i).Type = "button" Then
'objCollection(i).Value = True
The webpage gives me an error:
â—¾LOGIN ERROR: Security messages must be acknowledged by authorized
users to access e-OSCAR. Please try again.
like the radio button wasn't click, however, I can clearly see it's clicked. I commented that piece out, then ran it, the webpage pulls up with all 3 input boxes filled out, and the radio button checked. When I click "Login" it throws the same error. So it must be with the radio button itself or the way I'm trying to "click" it, not the code that's actually clicking the button "Login"
Does anyone have any thoughts (or recommendations that may resolve this) on why this might be happening?
- IE 11
- Excel 2013

Authentication from excel VBA

I am trying some internet explorer automation in excel VBA. When user press the button , he is taken to gmail, where he has to authenticate himself. After authentication, he is allowed to post data to a web service. Here is my code
Dim AppUrl As String
AppUrl = "https://mail.google.com"
Call NavigateToURL(AppUrl)
Public Sub NavigateToURL(argURL)
Dim LoginURL As String
Dim ServiceUrl As String
Dim objIE As Object
Dim URl As String
LoginURL = "https://mail.google.com/mail/u/0/#inbox"
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = True
.Silent = False
.Navigate argURL
While IE.Busy
DoEvents
Wend
Do
If objIE.LocationURL()= LoginURL Then
MsgBox("Successfully Authenticated")
Call requestPost 'to post excel data to a webservice
Exit Do
Else
MsgBox("Authentication failed")
End If
Loop While objIE.LocationURL() <> (LoginURL)
End With
End Sub
But the problem I face is as soon as https://mail.google.com loads completely, the if condition is checked and displays the message authentication failed. I want the program to wait till https://mail.google.com/mail/u/0/#inbox loads. Is there a way to do that?
Instead of using
While IE.Busy
DoEvents
Wend
try Application.Wait Now + TimeSerial(0, 0, 4) instead