,所以我写一些VBA代码步骤通过网站,我不断收到“对象变量或与块变量未设置错误”我通常可以通过以下步骤代码没有错误,这导致我相信这是一个时间问题。我用wait语句加载了这段代码,仍然会出现这个错误。有什么想法吗?我在做一些疯狂的事情吗?VBA对象变量或与块变量未设置错误 - 网页抓取
Sub Do_Work_Son()
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim plnSelect As HTMLSelectElement 'this selects the plan
Dim adrInput As HTMLInputElement 'this selects the address
Dim dirSelect As HTMLSelectElement 'this selects the distance
Dim strSQL As String
Dim LString As String
Dim LArray() As String
strSQL = "http://avmed.prismisp.com/?tab=doctor"
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate strSQL
Do Until .readyState = READYSTATE_COMPLETE: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:5"))
Set doc = IE.document
'Call WaitBrowser(IE)
'-----------------------------
'--Start Page Select Criteria--
'-----------------------------
Set plnSelect = doc.getElementsByClassName("full jqSelectPlan")(0)
plnSelect.selectedIndex = 1
Set adrInput = doc.getElementsByClassName("address-type-ahead enteredText ac_input defaultText")(0)
adrInput.Value = "32258" 'this is where we will link to zip code table
Set dirSelect = doc.getElementsByName("Proximity")(0)
dirSelect.selectedIndex = 0
doc.getElementsByClassName("button large")(0).click 'this submits the initial page
'------------------------------------------------------
'Call WaitBrowser(IE)
Application.Wait (Now + TimeValue("0:00:03"))
Debug.Print (doc.getElementsByClassName("profileDetails")(0).innerText)
LString = doc.getElementsByClassName("profileDetails")(0).innerText
LArray = Split(LString, vbCrLf)
Debug.Print (LArray(0))
Application.Wait (Now + TimeValue("0:00:2"))
Sheet1.Range("A1") = LArray(0)
Sheet1.Range("B1") = LArray(2)
Sheet1.Range("C1") = LArray(3)
Sheet1.Range("D1") = LArray(4)
Sheet1.Range("E1") = LArray(5)
Sheet1.Range("F1") = LArray(6)
End With
End Sub
哪一行出错? –
我看不到你在哪里设置'Sheet1'到任何东西。 –
捎带@MattCremeens - 你的意思是'Sheets(“Sheet1”)。Range(“A1”)...'? – BruceWayne