snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub GMAIL_Login()
'Set a reference (VBE > Tools > References) to the following libraries:
' 1) Microsoft Internet Controls
' 2) Microsoft HTML Object Library
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLElement As MSHTML.IHTMLElement
With IE
.Visible = True
.Silent = True
.navigate "https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin"
Do While .Busy Or .readyState <> READYSTATE_COMPLETE
DoEvents
Loop
End With
Call WaitAFewSeconds
Set HTMLDoc = IE.document
HTMLDoc.all.Email.Value = "nutpochan1@gmail.com"
HTMLDoc.all.SignIn.Click
With IE
Do While .Busy Or .readyState <> READYSTATE_COMPLETE
DoEvents
Loop
End With
Call WaitAFewSeconds
For Each HTMLElement In HTMLDoc.getElementsByName("Passwd")
If HTMLElement.getAttribute("type") = "password" Then
HTMLElement.Value = "mypassword"
Exit For
End If
Next HTMLElement
HTMLDoc.all.SignIn.Click
Set IE = Nothing
Set HTMLDoc = Nothing
Set HTMLElement = Nothing
End Sub
Private Sub WaitAFewSeconds()
Dim sngStart As Single
Const PAUSE_TIME As Integer = 5 'seconds
sngStart = Timer
Do Until Timer - sngStart > PAUSE_TIME
DoEvents
Loop
End Sub