Access & VBA: web page complex control

◇◆丶佛笑我妖孽 提交于 2020-03-27 07:02:46

问题


from my application in Access & VBA I have to open a login web page in a web application (developed from other company). After, I have to fill the form and login. After correct login, the app closes the browser automatically and open an other web page with the first user page.

Now, the problem is that the second web page works correctly only if I put a certain msg box; in other case, I see a "not set variable" in the indicated block.

Why? I would that, all works correctly without any msg box. Thank all!

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

来源:https://stackoverflow.com/questions/44341442/access-vba-web-page-complex-control

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!