Code:
Option Explicit
'Reference libraries to be added
'1. Microsoft HTML Object Library (mshtml.tlb)
'2. Microsoft Internet Controls (ieframe.dll)
Const strWaitTime As String = "00:00:00"
Const strURL = "http://www.gmail.com/"
Const strLoginID As String = "loginID"
Const strPWD As String = "password"
Dim strURLMain As String
Sub GmailLogin()
'ASSUMPTION: THE HOST SYSTEM HAS INTERNET EXPLORER VERSION 5 OR GREATER INSTALLED
Dim IE As InternetExplorer
Dim htmlUserNameTextBox As HTMLTextElement
Dim htmlUserPswdTextBox As HTMLTextElement
strURLMain = strURL
ErrH:
Err.Clear: On Error GoTo -1: On Error GoTo 0: On Error GoTo ErrH
If Not IE Is Nothing Then
IE.Quit
Set IE = Nothing
End If
'Start the internet explorer
Set IE = New InternetExplorer
IE.Visible = True
'Wait for a while (not necessary, but just in case we want to slow down the frequency of hit to the server) [Ditto wherever used]
Application.Wait Now() + TimeValue(strWaitTime)
'Navigate to the main URL
IE.Navigate strURLMain
'Hold your horses (so to say) till the page is ready :) [Ditto wherever used]
IESTATUS IE
'Pass credentials and click the login / submit button
Set htmlUserNameTextBox = IE.document.all("Email")
Set htmlUserPswdTextBox = IE.document.all("Passwd")
htmlUserNameTextBox.Value = strLoginID
htmlUserPswdTextBox.Value = strPWD
IE.document.all("signIn").Click
IESTATUS IE
ErH:
MsgBox Err.Description, vbCritical + vbOKOnly, "Unexpected Error"
IE.Quit
End Sub
Private Sub IESTATUS(ByVal IE As InternetExplorer)
Do While IE.Busy = True: Loop
Do Until IE.readystate = 4: Loop
End Sub
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
Bookmarks