我是VBA和编程的新手,我发现了一些在线代码来自动化网页处理。现在我只是想登录到电子奥斯卡的网页:网页自动化使用VBA
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now())
Loop
Set objCollection = IE.document.getElementsByTagName("input")
Set objName = IE.document.getElementsByTagName("name")
i = 0
While i < objCollection.Length
If objCollection(i).ID = "companyId" Then
' Set text for search
objCollection(i).Value = "companyId"
Else
If objCollection(i).ID = "userId" Then
objCollection(i).Value = "uId"
Else
If objCollection(i).ID = "password" Then
objCollection(i).Value = "pwd"
Else
If objCollection(i).ID = "securityMsgAck1" Then
objCollection(i).Value = True
'Else
'If objName(i).Name = "securityMsgAck" Then
'objName(i).Value = True
'Else
'If objCollection(i).ID = "button" Then
'objCollection(i).Value = True
' "Search" button is found
Set objElement = objCollection(i)
End If
End If
End If
End If
'End If
'End If
i = i + 1
Wend
objElement.Click ' click button to search
当以AS-IS运行时。这段代码打开了我试图自动化的网页,填写了公司ID,用户ID,密码,并且似乎检查了我确认该页面的T & C的框。但是,每当我去掉了“securityMsgAck”它不再检查框,并给我一个错误:
Run-time error '91': Object variable or With block variable not set.\
它也做到这一点,如果我注释掉“securityMsgAck”,并取消了“按钮”。看起来,我的代码试图检查框,只要这两个部分没有执行,但是当它们是声明要么失败之前,它可以尝试按下,或者他们完全阻止它。我不太确定...任何意见,将不胜感激。提前致谢。
编辑:每当我取消了该代码的任何部分,我的计划也将不再填写公司ID,用户ID或密码,有没有检查安全消息框沿...
“按钮”不会在本页面上存在的ID,你应该使用类“BTN” – h2so4
@ H2SO4嗯,这是非常合情合理的,但我的计划是在至少“尝试”登录(我认为)它现在的样子。我知道这是因为我收到来自网页的错误,在尝试登录之前,我没有“检查标记”安全消息来确认它。 – DukeLuke