1

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?

1 Answer 1

1

Instead of using

While IE.Busy
DoEvents
Wend

try Application.Wait Now + TimeSerial(0, 0, 4) instead

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.