从Excel VBAvalidation

我正在尝试一些在Excel VBA中的Internet Explorer自动化。 当用户按下button时,他被带到gmail,他必须在那里authentication自己。 authentication之后,他可以将数据发布到Web服务。 这是我的代码

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 

但我面对的问题是一旦https://mail.google.com加载完成,if条件被检查并显示消息身份validation失败。 我希望程序等待https://mail.google.com/mail/u/0/#inbox加载。 有没有办法做到这一点?

而不是使用

 While IE.Busy DoEvents Wend 

请尝试Application.Wait Now + TimeSerial(0, 0, 4)