,所以我寫一些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