通过VBA代码手动循环input数据到networking,但点击button不

使用Excel 2013login网站并自动更改数据。

以下代码完美地打开网站,input用户名和密码,“login”,并打开下一个屏幕。

然后它应该在新的屏幕上填充另外两个框,但是不是。 它生成一个运行时错误,说“对象是必需的”。

但是,如果我从错误行按“debugging”和“步进”,代码运行完美!

Option Explicit Sub EnterWeb() Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") Dim uRl As String Dim UserN As Object 'MSHTML.IHTMLElement Dim PW As Object 'MSHTML.IHTMLElement Dim CoNum As Object 'MSHTML.IHTMLElement Dim AuthCode As Object 'MSHTML.IHTMLElement Dim SUBMIT As Object 'MSHTML.IHTMLElement 'STAGE 1 - LOG INTO THE WEBSITE 'Set the website uRl = "WEBSITE NAME GOES HERE" With IE .navigate uRl .Visible = True End With ' loop until the page finishes loading Do While IE.Busy Loop 'Enter User name in "e-mail" textbox Set UserN = IE.document.getElementByID("email") If Not UserN Is Nothing Then UserN.Value = "TEXT GOES HERE" End If 'Enter Password in "Password" textbox Set PW = IE.document.getElementByID("seccode") If Not PW Is Nothing Then PW.Value = "TEXT GOES HERE" End If 'Sign in to site Dim Item As Object Set Item = IE.document.getElementsByClassName("button positive regular") Item.Item(0).Click 'STAGE 2 -ENTER DETAILS ON NEXT PAGE 'Enter in First textbox 'THIS IS WHERE THE PROBLEM STARTS. 'RUNNING MACRO AUTOMATICALLY GENERATES A RUNTIME ERROR 424 - "OBJECT REQUIRED" 'BUT STEPPING THROUGH USING F8 IT RUNS PERFECTLY Set CoNum = IE.document.getElementByID("PUTS ID HERE") If Not CoNum Is Nothing Then CoNum.Value = "PUTS VALUE HERE" End If 'Enter Code in textbox Set AuthCode = IE.document.getElementByID("PUTS CODE HERE") If Not AuthCode Is Nothing Then AuthCode.Value = "PUTS TEXT HERE" End If End Sub 

所有的build议感激地收到

Ochimus

扩展等待期以包含.readtState并允许通过消息队列泵进行处理,而不是locking它。

 Do While IE.Busy or ie.readystate <> 4 'READYSTATE_COMPLETE = 4 doevents Loop 

点击后,您也不会等待。 在.Click以及在开始尝试Set对象之前放置另一个。

这应该确保您收到标准页面。 如果在满足这些条件的时候尚未到达dynamic内容,还有其他方法可以实现。