The Whatsapp does not run with the Internetexplorer, therefore use Set IE = CreateObject("internetexplorer.application")
will not work because when opening the page in IE, the following screen appears:
IMPORTANT: You must use the latest version of Chrome, Firefox, Opera, Safari or Edge browsers in order to use Whatsapp Web. Other browsers like Internet Explorer do not support the application.
Why can’t I connect to Whatsapp Web?
You can use in other browsers, but you will need to use other references. As for example this API or use another program, such as Selenium.
To automate other browsers, there are numerous applications and software to accomplish this.
If you want to see the html code of the site and save it, use the following code:
Option Explicit
#If VBA7 Then
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub PraticarInternetExplorer()
Dim IE As InternetExplorer
Dim HTMLDoc As HTMLDocument
Dim teste As Object
Dim n As Long
Set IE = New InternetExplorer 'Set IE = CreateObject("InternetExplorer.Application")
Dim sFilename As String, sFilepath As String
Dim objStream As Object
Dim strData As String
Set objStream = CreateObject("ADODB.Stream")
sFilename = "temp.txt"
sFilepath = ThisWorkbook.Path & "\" & sFilename
With IE
.Silent = True
.Visible = True
.Navigate "https://web.whatsapp.com/"
End With
WaitIE IE, 5000
Set HTMLDoc = IE.Document
' Debug.Print HTMLDoc.DocumentElement.innerText
objStream.Type = 2 'Specify stream type - we want To save text/string data.
objStream.Charset = "utf-8" 'Specify charset For the source text data.
objStream.Open 'Open the stream And write binary data To the object
objStream.WriteText HTMLDoc.DocumentElement.innerHTML
objStream.SaveToFile sFilepath, 2 'Save binary data To disk
'close down IE and reset status bar
objStream.Close
IE.Quit
Set IE = Nothing
End Sub
Sub WaitIE(IE As Object, Optional time As Long = 250)
'Code from: https://stackoverflow.com/questions/33808000/run-time-error-91-object-variable-or-with-block-variable-not-set
Dim i As Long
Do
Sleep time
Debug.Print CStr(i) & vbTab & "Ready: " & CStr(IE.READYSTATE = 4) & _
vbCrLf & vbTab & "Busy: " & CStr(IE.Busy)
i = i + 1
Loop Until IE.READYSTATE = 4 Or Not IE.Busy
End Sub
If what you want is inside
class="app-wrapper app-wrapper-web"
, you need to use thegetElementByClassName
.– danieltakeshi
Even using "getElementByClassName" it keeps giving error 438.
– Gustavo_Tavares
Related
– danieltakeshi