【发布时间】:2015-05-29 23:15:41
【问题描述】:
在 VBA 中有以下代码用于下拉选择。
当我运行它时,我在粗体行上看到错误“运行时错误 91 - 对象变量或未设置块变量” ..New to VBA ....
Sub NACDP()
' open IE, navigate to the desired page and loop until fully loaded
Set ie = CreateObject("InternetExplorer.Application")
my_url = "https://cdeployna.cognizant.com/"
With ie
.Visible = True
.Navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
End With
' Input the userid and password
ie.Document.getElementById("loginControl_UserName").Value = ""
ie.Document.getElementById("loginControl_Password").Value = ""
' Click the "Login" button
ie.Document.getElementById("loginControl_LoginButton").Click
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
ie.Document.getElementById("ctl00_ddlRoles").selectedindex = 1
ie.Document.getElementById("ctl00_ddlRoles").FireEvent ("onchange")
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_ddlFieldName").selectedindex = 1
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_ddlFieldName").FireEvent ("onchange")
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_txtValue").Value = "Java"
' Click the "Search" button
ie.Document.getElementById("ctl00_ContentBody_searchCDPList_btnSearch").Click
End Sub
【问题讨论】:
-
您的粗体已在格式中丢失。请将有问题的代码行复制并粘贴到您的问题中作为编辑。
-
是哪一行导致上面的错误信息?
标签: vba internet-explorer excel