訪問時墜毀,並沒有錯誤調用此VBA:調用函數
Public IE As InternetExplorer
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
Dim el As Object
Public Function IEClick(Idstr As String)
Do
Set el = Nothing
On Error Resume Next
Set el = IE.Document.getElementById(Idstr)
On Error GoTo 0
DoEvents
Sleep (100)
Loop While el Is Nothing
Sleep (1000)
IE.Document.getElementById(Idstr).Click
End Function
其時,真正的循環,直到找到正確的elementid我有一個問題。當這個函數被調用像這樣的時候,我在這條線上沒有錯誤信息IEClick Str(Item)
。
For Each Item In coll
IEClick Str(Item)
p = p + 1
Next
這是完整的代碼體。
Public Sub AutoExtract()
Dim ProgressBar_Extract As Object
Dim coll As Collection
Set coll = New Collection
'/////////////////controls in order///////////////
With coll
.Add "ctl00_cmdCustom"
.Add "chkAll"
.Add "ctl00_cmdContinue"
End With
Me.ProgressBar_Extract.Max = coll.Count
'////////////////////start ie//////////////////
Set IE = New InternetExplorerMedium
With IE
'.AddressBar = False
'.MenuBar = False
.Navigate ("*****")
.Visible = True
End With
'//////////////////////Start Automation///////////////////
For Each Item In coll
IEClick Str(Item)
p = p + 1
Next
MsgBox "Extract Complete"
End Sub
我把範圍縮小到IEClick Str(Item)
。當調試,如果我制止它,一步下一個崩潰行。
*「沒有錯誤信息時崩潰」*是什麼意思?它鎖定?或者它關閉(然後Access進程仍然運行?)? – Andre
@Andre關閉進程沒有運行。 – Quint
作爲第一步,我推薦一個完整的[反編譯](http://stackoverflow.com/a/3268188/3820271)。 – Andre