访问& VBA:网页复杂控制

时间:2017-06-03 07:18:23

标签: vba ms-access web

来自我在Access&中的应用程序VBA我必须在Web应用程序中打开一个登录网页(从其他公司开发)。之后,我必须填写表格并登录。正确登录后,应用程序会自动关闭浏览器,并打开第一个用户页面的其他网页。

现在,问题是第二个网页只有在我放了一个msg框时才能正常工作;在其他情况下,我在指示的块中看到“未设置变量”。

为什么呢?我会这样,所有工作正常没有任何消息框。谢谢大家!

Private Sub managerDocsPa()

Dim ie As Object
Dim IeDoc As HTMLDocument
Set ie = CreateObject("InternetExplorer.application")
ie.Navigate ("http://myapp.com/login.aspx")
ie.Visible = True
Do While ie.Busy: DoEvents: Loop
Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set IeDoc = ie.Document

With IeDoc
       'MsgBox .title
      .getElementById("userid").Value = "myuser"
      .getElementById("password").Value = "mypass"
      .getElementById("btn_login").Click
End With

Do While ie.Busy: DoEvents: Loop
Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer
Dim winShell As Shell
Dim dt As Date
dt = DateAdd("s", 10, DateTime.Now)
Dim ieA As InternetExplorer
Dim IeDocA As HTMLDocument
Do While dt > DateTime.Now

   Set winShell = New Shell

   For Each ieA In winShell.Windows
       If ieA.LocationURL = sURL Then

       ieA.Visible = True
       ieA.Silent = True

       Do While ieA.Busy: DoEvents: Loop
       Do Until ieA.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
       Set IeDocA = ieA.Document

       //Why it works only with this message?
       MsgBox "abc"


       //Without the message, at this point I see the error
       With IeDocA
           .getElementsByName("sampleButton")(0).Click
       End With

       Set winShell = Nothing
       Exit Do

       End If

   Next ieA
   Set winShell = Nothing
   DoEvents

Loop

End Sub

0 个答案:

没有答案