“对象变量或with块变量未设置”的错误。大家帮我看看怎么改阿。多谢!

Charlie_YAN 2009-01-06 06:00:09
Sub LoginToURL(userID As String)

Dim ie As Object, iebody As String, strURL As String, strUsername As String, strPassword As String

Set ie = CreateObject("InternetExplorer.Application")

strURL = "http://192.168.0.101/kanyos2/Student/StudentTranscript.aspx?studentID=" & userID
strUsername = "admin"
strPassword = "000000"

ie.Navigate strURL
'Wait until page is loaded.
While ie.ReadyState < 4 ' READYSTATE_COMPLETE = 4
DoEvents
Wend

ie.Document.Visible = True

ie.Document.All("ctl00_ContentPlaceHolder1_UserId").Value = strUsername
ie.Document.All("ctl00_ContentPlaceHolder1_Password").Value = strPassword
ie.Document.All("ctl00_ContentPlaceHolder1_login").Click



'Wait until page is loaded.
While ie.ReadyState < 4 ' READYSTATE_COMPLETE = 4
DoEvents
Wend

Application.Wait (Now + TimeValue("0:00:05"))

iebody = ie.Document.body.innerhtml

If InStr(iebody, "The information you entered is invalid.") <> 0 Then
MsgBox "Login failed!", vbCritical + vbOKOnly
Else
MsgBox "Login successful!", vbInformation + vbOKOnly
End If

ie.ExecWB 6, 6

ie.Quit
Set ie = Nothing

End Sub

其中这段代码循环调用,老在ie.Document.All("ctl00_ContentPlaceHolder1_UserId").Value = strUsername这一行报“对象变量或with块变量未设置”的错误。大家帮我看看怎么改阿。多谢!
...全文
102 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧