求助,vba错误:运行时错误91:对象变量或with变量未设置
学习vba时,遇到一个小问题,再网上找了很久都没能找到解决办法,发帖求助。代码如下,
Private Sub Workbook_Open()
' On Error GoTo Err_handle
'
'填入网页
'
'
Dim k As Integer
k = 1
Dim myIE As InternetExplorerMedium
'第一列不为空,即id不为空
'cells(行,列),都是从1开始
Set sht = ThisWorkbook.Worksheets("sheet1")
Set myIE = New InternetExplorerMedium
Do While sht.Cells(k, 1) <> ""
x = sht.Cells(k, 10)
'不为Y,就执行
If x <> "Y" Then
With myIE
.Visible = True
.Navigate "网址"
End With
'页面加载完成才执行接下来的语句
With myIE
While .ReadyState <> 4 Or .Busy
DoEvents
Wend
.Document.getElementById("userid").Value = "KNET"
.Document.getElementById("pwd").Value = "123456"
.Document.getElementsByName("Submit")(0).Click
While .ReadyState <> 4 Or .Busy
DoEvents
Wend
Application.Wait Now + TimeValue("0:00:01")
.Document.getElementsByName("S_SITE_SELF_SERVICE")(0).Click
While .ReadyState <> 4 Or .Busy
DoEvents
Wend
Application.Wait Now + TimeValue("0:00:01")
.Document.getElementsByName("S_SITE_ABSENCE")(0).Click
While .ReadyState <> 4 Or .Busy
DoEvents
Wend
Application.Wait Now + TimeValue("0:00:01")
.Document.getElementsByName("S_ABSBL_CN_GBL")(0).Click
While .ReadyState <> 4 Or .Busy
DoEvents
Wend
myIE.Document.getElementById("S_ABSBL_SRCH_VW_EMPLID").Value = sht.Cells(k, 1)
While .ReadyState <> 4 Or .Busy
DoEvents
Wend
Application.Wait Now + TimeValue("0:00:03")
.Quit
End With
'填写完毕就设置为Y
' sht.Cells(k, 10).Value = "Y"
End If
k = k + 1
Loop
MsgBox "finish"
Err_handle:
If Err.Description <> "" Then
MsgBox Err.Description
End If
End Sub
调试的时候发现是黑体的地方出的问题,希望各位大佬帮我看看