(急)对象变量或with块变量未设置 大家来帮我看看啊

Charlie_YAN 2009-01-06 05:39:53
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块变量未设置”的错误。大家帮我看看怎么改阿。多谢!
...全文
69 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
setoption9 2009-01-07
友情up
  • 打赏
  • 举报
回复
noenoughmemory 2009-01-07
友情up
  • 打赏
  • 举报
回复
sonic_andy 2009-01-06
有可能是ie.Document.All("ctl00_ContentPlaceHolder1_UserId").Value 中Value前边指定的对象不存在导致的..
  • 打赏
  • 举报
回复
相关推荐
发帖
VBA
加入

2111

社区成员

VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
申请成为版主
帖子事件
创建了帖子
2009-01-06 05:39
社区公告
暂无公告